ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2024-08-03 06:15:10
Exec Total Coverage
Lines: 2776 8329 33.3%
Functions: 76 290 26.2%
Branches: 2402 7193 33.4%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "zq/zquestdat.h"
29 #include "base/zsys.h"
30 #include "sprite.h"
31 #include "items.h"
32 #include "zc/zc_sys.h"
33 #include "md5.h"
34 #include "zc/zc_custom.h"
35 #include "subscr.h"
36 #include "zq/zq_strings.h"
37 #include "zq/zq_subscr.h"
38 #include "zc/ffscript.h"
39 #include "base/util.h"
40 #include "zq/zq_files.h"
41 #include "dialog/alert.h"
42 #include "slopes.h"
43 #include "drawing.h"
44 #include "zinfo.h"
45 #include "zq/render_minimap.h"
46 #include "base/mapscr.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57 extern FFScript FFCore;
58
59 extern ZModule zcm;
60 extern zcmodule moduledata;
61 extern uint8_t ViewLayer3BG, ViewLayer2BG;
62 extern int32_t LayerDitherBG, LayerDitherSz;
63 extern bool NoHighlightLayer0;
64
65 using std::string;
66 using std::pair;
67 #define EPSILON 0.01 // Define your own tolerance
68 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
69
70 #define COLOR_SOLID vc(4)
71 #define COLOR_SLOPE vc(13)
72 #define COLOR_LADDER vc(6)
73 //#define COLOR_EFFECT vc(10)
74
75 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
76 extern char msgbuf[MSG_NEW_SIZE*8];
77
78 extern string zScript;
79
80 9 zmap Map;
81 int32_t prv_mode=0;
82 int16_t ffposx[MAXFFCS];
83 int16_t ffposy[MAXFFCS];
84 int32_t ffprvx[MAXFFCS];
85 int32_t ffprvy[MAXFFCS];
86 void init_ffpos()
87 {
88 for (word q = 0; q < MAXFFCS; ++q)
89 {
90 ffposx[q] = -1000;
91 ffposy[q] = -1000;
92 ffprvx[q] = -10000000;
93 ffprvy[q] = -10000000;
94 }
95 }
96
97 bool save_warn=true;
98
99 int32_t COMBOPOS(int32_t x, int32_t y)
100 {
101 return (((y) & 0xF0) + ((x) >> 4));
102 }
103 int32_t COMBOPOS_B(int32_t x, int32_t y)
104 {
105 if(unsigned(x) >= 256 || unsigned(y) >= 176)
106 return -1;
107 return COMBOPOS(x,y);
108 }
109 int32_t COMBOX(int32_t pos)
110 {
111 return ((pos) % 16 * 16);
112 }
113 int32_t COMBOY(int32_t pos)
114 {
115 return ((pos) & 0xF0);
116 }
117
118 void reset_dmap(int32_t index)
119 {
120 bound(index,0,MAXDMAPS-1);
121 DMaps[index].clear();
122 DMaps[index].title = "";
123 sprintf(DMaps[index].intro, " ");
124 }
125
126 void reset_dmaps()
127 {
128 for(int32_t i=0; i<MAXDMAPS; i++)
129 reset_dmap(i);
130 }
131
132 void truncate_dmap_title(std::string& title)
133 {
134 title.resize(21, ' ');
135 }
136
137 mapscr* zmap::get_prvscr()
138 {
139 return &prvscr;
140 }
141
142
7/12
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 90 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 18 times.
108 zmap::zmap()
143 {
144 18 can_paste=false;
145 18 prv_cmbcycle=0;
146 18 prv_advance=0;
147 18 prv_freeze=0;
148 18 copyffc=-1;
149
150 18 memset(scrpos, 0, sizeof(scrpos));
151 18 screens=NULL;
152 18 prv_time=0;
153 18 prv_scr=0;
154 18 prv_map=0;
155 18 copyscr=0;
156 18 currscr=0;
157 18 copymap=0;
158 18 currmap=0;
159 18 layer_target_map = 0;
160 18 layer_target_scr = 0;
161 18 layer_target_multiple = 0;
162
163 18 }
164 18 zmap::~zmap()
165 {
166 18 }
167
168 9 void zmap::clear()
169 {
170
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 *this = zmap();
171 9 }
172 void zmap::force_refr_pointer()
173 {
174 if(unsigned(currmap) > map_count || (currmap*MAPSCRS > TheMaps.size()))
175 screens = nullptr;
176 else screens = &TheMaps[currmap*MAPSCRS];
177 }
178 bool zmap::CanUndo()
179 {
180 return undo_stack.size() > 0;
181 }
182 bool zmap::CanRedo()
183 {
184 return redo_stack.size() > 0;
185 }
186 bool zmap::CanPaste()
187 {
188 return can_paste;
189 }
190 int32_t zmap::CopyScr()
191 {
192 return (copymap<<8)+copyscr;
193 }
194 int32_t zmap::getCopyFFC()
195 {
196 return copyffc;
197 }
198 set_ffc_command::data_t zmap::getCopyFFCData()
199 {
200 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
201 }
202 29 int32_t zmap::getMapCount()
203 {
204 29 return map_count;
205 }
206 int32_t zmap::getLayerTargetMap()
207 {
208 return layer_target_map;
209 }
210 int32_t zmap::getLayerTargetScr()
211 {
212 return layer_target_scr;
213 }
214 int32_t zmap::getLayerTargetMultiple()
215 {
216 return layer_target_multiple;
217 }
218 bool zmap::isDungeon(int32_t scr)
219 {
220 for(int32_t i=0; i<4; i++)
221 {
222 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
223 {
224 return false;
225 }
226 }
227
228 return true;
229 }
230
231 bool zmap::clearall(bool validate)
232 {
233 Color=0;
234 char tbuf[10];
235
236 if((header.templatepath[0]!=0)&&validate)
237 {
238 if(!valid_zqt(header.templatepath))
239 {
240 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
241 return false;
242 }
243 }
244
245 for(int32_t i=0; i<map_count; i++)
246 {
247 setCurrMap(i);
248 sprintf(tbuf, "%d", i);
249 clearmap(true);
250 }
251
252 setCurrMap(0);
253 return true;
254 }
255
256 bool zmap::reset_templates(bool validate)
257 {
258 //why are we doing this?
259 if(colordata==NULL)
260 {
261 return false;
262 }
263
264 char *deletefilename=(char *)malloc(1);
265 ASSERT(deletefilename);
266 deletefilename[0]=0;
267
268 //int32_t ret;
269 word version, build, dummy, sversion=0;
270 byte dummyc;
271 word dummyw;
272 //int32_t section_size;
273 word temp_map_count;
274 mapscr temp_mapscr;
275 PACKFILE *f=NULL;
276
277 // setPackfilePassword(datapwd);
278 f=open_quest_template(&header, deletefilename, validate);
279 get_version_and_build(f, &version, &build);
280
281 if(!find_section(f, ID_MAPS))
282 {
283 // setPackfilePassword(NULL);
284 return false;
285 }
286
287 //section version info
288 if(!p_igetw(&sversion,f))
289 {
290 return false;
291 }
292
293 if(!p_igetw(&dummy,f))
294 {
295 return false;
296 }
297
298 //section size
299 dword dummy_size;
300 if(!p_igetl(&dummy_size,f))
301 {
302 return false;
303 }
304
305 //finally... section data
306 if(!p_igetw(&temp_map_count,f))
307 {
308 return false;
309 }
310
311 if(version>12)
312 {
313 if(!p_getc(&dummyc,f))
314 return qe_invalid;
315
316 if(!p_getc(&dummyc,f))
317 return qe_invalid;
318
319 if(!p_igetw(&dummyw,f))
320 return qe_invalid;
321
322 if(!p_igetw(&dummyw,f))
323 return qe_invalid;
324
325 if(!p_igetw(&dummyw,f))
326 return qe_invalid;
327
328 if(!p_igetw(&dummyw,f))
329 return qe_invalid;
330
331 if(!p_igetw(&dummyw,f))
332 return qe_invalid;
333
334 if(!p_igetw(&dummyw,f))
335 return qe_invalid;
336
337 if(!p_igetw(&dummyw,f))
338 return qe_invalid;
339
340 if(!p_igetw(&dummyw,f))
341 return qe_invalid;
342
343 if(!p_igetw(&dummyw,f))
344 return qe_invalid;
345
346 if(!p_igetw(&dummyw,f))
347 return qe_invalid;
348
349 if(!p_getc(&dummyc,f))
350 return qe_invalid;
351
352 if(!p_getc(&dummyc,f))
353 return qe_invalid;
354 }
355
356 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
357 {
358 readmapscreen(f, &header, &temp_mapscr, sversion);
359 }
360
361 readmapscreen(f, &header, &TheMaps[128], sversion);
362 readmapscreen(f, &header, &TheMaps[129], sversion);
363
364 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
365 {
366 readmapscreen(f, &header, &temp_mapscr, sversion);
367 }
368
369 if(version>12)
370 {
371 if(!p_getc(&dummyc,f))
372 return qe_invalid;
373
374 if(!p_getc(&dummyc,f))
375 return qe_invalid;
376
377 if(!p_igetw(&dummyw,f))
378 return qe_invalid;
379
380 if(!p_igetw(&dummyw,f))
381 return qe_invalid;
382
383 if(!p_igetw(&dummyw,f))
384 return qe_invalid;
385
386 if(!p_igetw(&dummyw,f))
387 return qe_invalid;
388
389 if(!p_igetw(&dummyw,f))
390 return qe_invalid;
391
392 if(!p_igetw(&dummyw,f))
393 return qe_invalid;
394
395 if(!p_igetw(&dummyw,f))
396 return qe_invalid;
397
398 if(!p_igetw(&dummyw,f))
399 return qe_invalid;
400
401 if(!p_igetw(&dummyw,f))
402 return qe_invalid;
403
404 if(!p_igetw(&dummyw,f))
405 return qe_invalid;
406
407 if(!p_getc(&dummyc,f))
408 return qe_invalid;
409
410 if(!p_getc(&dummyc,f))
411 return qe_invalid;
412 }
413
414 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
415 {
416 readmapscreen(f, &header, &temp_mapscr, sversion);
417 }
418
419 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
420 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
421
422 pack_fclose(f);
423 clear_quest_tmpfile();
424
425 if(deletefilename[0]==0)
426 {
427 delete_file(deletefilename);
428 }
429
430
431 return true;
432 }
433
434 bool zmap::clearmap(bool newquest)
435 {
436 if(currmap<map_count)
437 {
438 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
439 {
440 clearscr(i);
441 }
442
443 setCurrScr(0);
444
445 if(newquest)
446 {
447 if(!reset_templates(false))
448 {
449 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
450 }
451 }
452 }
453
454 return true;
455 }
456
457 mapscr* zmap::CurrScr()
458 {
459 return screens+currscr;
460 }
461 mapscr* zmap::Scr(int32_t scr)
462 {
463 return screens+scr;
464 }
465 mapscr* zmap::AbsoluteScr(int32_t scr)
466 {
467 if(unsigned(scr) >= MAPSCRS*getMapCount())
468 return nullptr;
469 return &TheMaps[scr];
470 }
471 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
472 {
473 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
474 return nullptr;
475 return AbsoluteScr((map*MAPSCRS)+scr);
476 }
477 void zmap::set_prvscr(int32_t map, int32_t scr)
478 {
479 prvscr=TheMaps[(map*MAPSCRS)+scr];
480
481 for(int32_t i=0; i<6; i++)
482 {
483 if(prvscr.layermap[i]>0)
484 {
485 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
486 }
487 else
488 prvlayers[i].valid = 0;
489 }
490
491 prv_map=map;
492 prv_scr=scr;
493 }
494 71 int32_t zmap::getCurrMap()
495 {
496 71 return currmap;
497 }
498 bool zmap::isDark()
499 {
500 return (screens[currscr].flags&fDARK)!=0;
501 }
502
503 void zmap::setCurrentView(int32_t map, int32_t scr)
504 {
505 bool change_view = map != Map.getCurrMap() || scr != Map.getCurrScr();
506 if (map != Map.getCurrMap()) Map.setCurrMap(map);
507 if (scr != Map.getCurrScr()) Map.setCurrScr(scr);
508 if (change_view)
509 {
510 refresh(rALL);
511 rebuild_trans_table();
512 }
513 }
514
515 9 void zmap::setCurrMap(int32_t index)
516 {
517 9 int32_t oldmap=currmap;
518 9 optional<int> oldcolor;
519
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(screens)
520 oldcolor = getcolor();
521 9 scrpos[currmap]=currscr;
522 9 currmap=bound(index,0,map_count);
523 9 screens=&TheMaps[currmap*MAPSCRS];
524
525 9 currscr=scrpos[currmap];
526 9 int newcolor = getcolor();
527 9 loadlvlpal(newcolor);
528
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(!oldcolor || *oldcolor != newcolor)
529 9 rebuild_trans_table();
530
531 9 reset_combo_animations2();
532 9 mmap_mark_dirty();
533 9 }
534
535 17 int32_t zmap::getCurrScr()
536 {
537 17 return currscr;
538 }
539 9 void zmap::setCurrScr(int32_t scr)
540 {
541
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if(scr==currscr) return;
542
543 8 int32_t oldscr=currscr;
544 8 int32_t oldcolor=getcolor();
545
546
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if(!(screens[currscr].valid&mVALID))
547 {
548 2 oldcolor=-1;
549 2 }
550
551 8 currscr=bound(scr,0,MAPSCRS-1);
552 8 int32_t newcolor=getcolor();
553 8 loadlvlpal(newcolor);
554
555 //setcolor(newcolor);
556
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!(screens[currscr].valid&mVALID))
557 {
558 newcolor=-1;
559 }
560
561
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if(newcolor!=oldcolor)
562 {
563 7 rebuild_trans_table();
564 7 }
565
566 8 reset_combo_animations2();
567 8 setlayertarget();
568 8 mmap_mark_dirty();
569 9 }
570
571 8 void zmap::setlayertarget()
572 {
573 8 layer_target_map = 0;
574 8 layer_target_multiple = 0;
575
576
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 8 times.
29 for(int32_t m=0; m<getMapCount(); ++m)
577 {
578
2/2
✓ Branch 0 taken 2856 times.
✓ Branch 1 taken 21 times.
2877 for(int32_t s=0; s<MAPSCRS; ++s)
579 {
580 2856 int32_t i=(m*MAPSCRS+s);
581 2856 mapscr *ts=&TheMaps[i];
582
583 // Search through each layer
584
2/2
✓ Branch 0 taken 17136 times.
✓ Branch 1 taken 2856 times.
19992 for(int32_t w=0; w<6; ++w)
585 {
586
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 17134 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
17136 if(ts->layerscreen[w]==currscr && (ts->layermap[w]-1)==currmap)
587 {
588 if(layer_target_map > 0)
589 {
590 layer_target_multiple += 1;
591 continue;
592 }
593
594 layer_target_map = m+1;
595 layer_target_scr = s;
596 }
597 17136 }
598 2856 }
599 21 }
600 8 }
601
602 void zmap::setcolor(int32_t c)
603 {
604 screens[currscr].valid |= mVALID;
605 screens[currscr].color = c;
606
607 if(Color!=c)
608 {
609 Color = c;
610 loadlvlpal(c);
611 rebuild_trans_table();
612 }
613
614 mmap_mark_dirty();
615 }
616
617 25 int32_t zmap::getcolor()
618 {
619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if(prv_mode)
620 {
621 return prvscr.color;
622 }
623
624 25 return screens[currscr].color;
625 25 }
626
627 void zmap::resetflags()
628 {
629 byte *di=&(screens[currscr].valid);
630
631 for(int32_t i=1; i<48; i++)
632 {
633 *(di+i)=0;
634 }
635 }
636
637 word zmap::tcmbdat(int32_t pos)
638 {
639 return screens[TEMPLATE].data[pos];
640 }
641
642 word zmap::tcmbcset(int32_t pos)
643 {
644 return screens[TEMPLATE].cset[pos];
645 }
646
647 int32_t zmap::tcmbflag(int32_t pos)
648 {
649 return screens[TEMPLATE].sflag[pos];
650 }
651
652 word zmap::tcmbdat2(int32_t pos)
653 {
654 return screens[TEMPLATE2].data[pos];
655 }
656
657 word zmap::tcmbcset2(int32_t pos)
658 {
659 return screens[TEMPLATE2].cset[pos];
660 }
661
662 int32_t zmap::tcmbflag2(int32_t pos)
663 {
664 return screens[TEMPLATE2].sflag[pos];
665 }
666
667 void zmap::TemplateAll()
668 {
669 StartListCommand();
670 for(int32_t i=0; i<128; i++)
671 {
672 if((screens[i].valid&mVALID) && isDungeon(i))
673 DoTemplateCommand(-1, i, currscr);
674 }
675 FinishListCommand();
676 }
677
678 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
679 {
680 if(scr==TEMPLATE)
681 return;
682
683 if(!(screens[scr].valid&mVALID))
684 screens[scr].color=Color;
685
686 screens[scr].valid|=mVALID;
687
688 for(int32_t i=0; i<32; i++)
689 {
690 screens[scr].data[i]=screens[TEMPLATE].data[i];
691 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
692 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
693 }
694
695 for(int32_t i=144; i<176; i++)
696 {
697 screens[scr].data[i]=screens[TEMPLATE].data[i];
698 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
699 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
700 }
701
702 for(int32_t y=2; y<=9; y++)
703 {
704 int32_t j=y<<4;
705 screens[scr].data[j]=screens[TEMPLATE].data[j];
706 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
707 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
708 ++j;
709 screens[scr].data[j]=screens[TEMPLATE].data[j];
710 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
711 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
712 ++j;
713 j+=12;
714 screens[scr].data[j]=screens[TEMPLATE].data[j];
715 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
716 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
717 ++j;
718 screens[scr].data[j]=screens[TEMPLATE].data[j];
719 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
720
721 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
722 ++j;
723 }
724
725 if(floorcombo!=-1)
726 {
727 for(int32_t y=2; y<9; y++)
728 for(int32_t x=2; x<14; x++)
729 {
730 int32_t i=(y<<4)+x;
731 screens[scr].data[i] = floorcombo;
732 screens[scr].cset[i] = floorcset;
733 }
734 }
735
736 for(int32_t i=0; i<4; i++)
737 putdoor(scr,i,screens[scr].door[i]);
738 }
739
740
741 void zmap::clearscr(int32_t scr)
742 {
743 screens[scr].zero_memory();
744 screens[scr].valid=mVERSION;
745 for(int q = 0; q < 6; ++q)
746 {
747 auto layer = map_autolayers[currmap*6+q];
748 screens[scr].layermap[q] = layer;
749 screens[scr].layerscreen[q] = layer ? scr : 0;
750 }
751 mmap_mark_dirty();
752 }
753
754 const char *loaderror[] =
755 {
756
757 "OK","File not found","Incomplete data",
758 "Invalid version","Invalid file"
759
760 };
761
762 int32_t zmap::load(const char *path)
763 {
764 PACKFILE *f=pack_fopen_password(path,F_READ, "");
765
766 if(!f)
767 return 1;
768
769
770 int16_t version;
771 byte build;
772
773 //get the version
774 if(!p_igetw(&version,f))
775 {
776 goto file_error;
777 }
778
779 //get the build
780 if(!p_getc(&build,f))
781 {
782 goto file_error;
783 }
784
785 for(int32_t i=0; i<MAPSCRS; i++)
786 {
787 mapscr tmpimportscr;
788 tmpimportscr.zero_memory();
789 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
790 {
791 al_trace("failed zmap::load\n");
792 goto file_error;
793 }
794
795 switch(ImportMapBias)
796 {
797 case 0:
798 *(screens+i) = tmpimportscr;
799 break;
800
801 case 1:
802 if(!(screens[i].valid&mVALID))
803 {
804 *(screens+i) = tmpimportscr;
805 }
806 break;
807
808 case 2:
809 if(tmpimportscr.valid&mVALID)
810 {
811 *(screens+i) = tmpimportscr;
812 }
813 break;
814 }
815 }
816
817
818 pack_fclose(f);
819
820 setCurrScr(0);
821 mmap_mark_dirty();
822 return 0;
823
824 file_error:
825 pack_fclose(f);
826 clearmap(false);
827 return 2;
828 }
829
830 int32_t zmap::save(const char *path)
831 {
832 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
833
834 if(!f)
835 return 1;
836
837 if(!p_iputw(V_MAPS,f))
838 {
839 pack_fclose(f);
840 return 3;
841 }
842
843 // This was the "build number", but that's totally useless here. Keep this junk byte
844 // so as not to totally break exports between ZC versions.
845 if(!p_putc(0,f))
846 {
847 pack_fclose(f);
848 return 3;
849 }
850
851 for(int32_t i=0; i<MAPSCRS; i++)
852 {
853 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
854 {
855 pack_fclose(f);
856 return 2;
857 }
858 }
859
860 pack_fclose(f);
861 return 0;
862 }
863
864
865 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
866 {
867 // Hookshots can be blocked by solid combos on all 3 ground layers.
868 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
869
870 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
871 return true;
872 if (c->walk&(1<<i))
873 return false;
874
875 for(int32_t k=0; k<2; k++)
876 {
877 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
878
879 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
880 {
881 return false;
882 }
883 }
884
885 return true;
886 }
887
888 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
889 {
890 // Hookshots can be blocked by solid combos on all 3 ground layers.
891 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
892
893 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
894 return true;
895 if (c->walk&(1<<i))
896 return false;
897
898 for(int32_t k=0; k<2; k++)
899 {
900 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
901
902 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
903 {
904 return false;
905 }
906 }
907
908 return true;
909 }
910
911 bool zmap::isstepable(int32_t combo)
912 {
913 // This is kind of odd but it's true to the engine (see maps.cpp)
914 return (combo_class_buf[combobuf[combo].type].ladder_pass);
915 }
916
917 // Returns the letter of the warp combo.
918 int32_t zmap::warpindex(int32_t combo)
919 {
920 switch(combobuf[combo].type)
921 {
922 case cCAVE:
923 case cPIT:
924 case cSTAIR:
925 case cCAVE2:
926 case cSWIMWARP:
927 case cDIVEWARP:
928 case cSWARPA:
929 return 0;
930
931 case cCAVEB:
932 case cPITB:
933 case cSTAIRB:
934 case cCAVE2B:
935 case cSWIMWARPB:
936 case cDIVEWARPB:
937 case cSWARPB:
938 return 1;
939
940 case cCAVEC:
941 case cPITC:
942 case cSTAIRC:
943 case cCAVE2C:
944 case cSWIMWARPC:
945 case cDIVEWARPC:
946 case cSWARPC:
947 return 2;
948
949 case cCAVED:
950 case cPITD:
951 case cSTAIRD:
952 case cCAVE2D:
953 case cSWIMWARPD:
954 case cDIVEWARPD:
955 case cSWARPD:
956 return 3;
957
958 case cPITR:
959 case cSTAIRR:
960 case cSWARPR:
961 return 4;
962 }
963
964 return -1;
965
966 }
967
968 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
969 {
970 if(top)
971 line(dest,x,y,x+15,y,c);
972 rectfill(dest,x,y,x+3,y+15,c);
973 rectfill(dest,x+12,y,x+15,y+15,c);
974 rectfill(dest,x+4,y+2,x+11,y+5,c);
975 rectfill(dest,x+4,y+10,x+11,y+13,c);
976 }
977
978 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
979 {
980 line(dest,x,y,x+15,y,c);
981 }
982
983 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
984 {
985 int32_t cx = COMBOX(pos);
986 int32_t cy = COMBOY(pos);
987
988 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
989
990 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
991
992 int32_t bridgedetected = 0;
993
994 for(int32_t i=0; i<4; i++)
995 {
996 int32_t tx=((i&2)<<2)+x;
997 int32_t ty=((i&1)<<3)+y;
998 int32_t tx2=((i&2)<<2)+cx;
999 int32_t ty2=((i&1)<<3)+cy;
1000 for (int32_t m = layer; m <= 1; m++)
1001 {
1002 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1003 {
1004 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1005 {
1006 bridgedetected |= (1<<i);
1007 }
1008 }
1009 else
1010 {
1011 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1012 {
1013 bridgedetected |= (1<<i);
1014 }
1015 }
1016 }
1017 if (bridgedetected & (1<<i))
1018 {
1019 if (i >= 3) break;
1020 else continue;
1021 }
1022 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1023 {
1024 for(int32_t k=0; k<8; k+=2)
1025 for(int32_t j=0; j<8; j+=2)
1026 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1027 }
1028 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1029 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1030
1031 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1032 {
1033 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1034 {
1035 for(int32_t k=0; k<8; k+=2)
1036 for(int32_t j=0; j<8; j+=2)
1037 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1038 }
1039 else
1040 {
1041 int32_t color = COLOR_SOLID;
1042
1043 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1044 color=vc(6);
1045 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1046 color=vc(7);
1047
1048 rectfill(dest,tx,ty,tx+7,ty+7,color);
1049 }
1050 }
1051 }
1052
1053 bridgedetected = 0;
1054 for(int32_t i=0; i<4; i++)
1055 {
1056 int32_t tx2=((i&2)<<2)+cx;
1057 int32_t ty2=((i&1)<<3)+cy;
1058 for (int32_t m = 0; m <= 1; m++)
1059 {
1060 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1061 {
1062 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1063 {
1064 bridgedetected |= (1<<i);
1065 }
1066 }
1067 else
1068 {
1069 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1070 {
1071 bridgedetected |= (1<<i);
1072 }
1073 }
1074 }
1075 }
1076
1077 // Draw damage combos
1078 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1079 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1080 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1081 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1082 || combo_class_buf[c1.type].modify_hp_amount
1083 || combo_class_buf[c2.type].modify_hp_amount;
1084
1085 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1086
1087 if(dmg)
1088 {
1089 if (bridgedetected <= 0)
1090 {
1091 for(int32_t k=0; k<16; k+=2)
1092 for(int32_t j=0; j<16; j+=2)
1093 if(((k+j)/2)%2)
1094 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1095 }
1096 else
1097 {
1098 for(int32_t i=0; i<4; i++)
1099 {
1100 if (!(bridgedetected & (1<<i)))
1101 {
1102 int32_t tx=((i&2)<<2)+x;
1103 int32_t ty=((i&1)<<3)+y;
1104 for(int32_t k=0; k<8; k+=2)
1105 for(int32_t j=0; j<8; j+=2)
1106 if(((k+j)/2)%2)
1107 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1108 }
1109 }
1110 }
1111 }
1112
1113 if(c.type == cSLOPE)
1114 {
1115 slope_info s(c, x, y);
1116 s.draw(dest, 0, 0, COLOR_SLOPE);
1117 }
1118 auto fl0 = MAPFLAG2(-1,cx,cy);
1119 auto fl1 = MAPFLAG2(0,cx,cy);
1120 auto fl2 = MAPFLAG2(1,cx,cy);
1121 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1122 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1123 {
1124 bool top = false;
1125 if(cy)
1126 {
1127 top = true;
1128 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1129 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1130 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1131 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1132 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1133 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1134 {
1135 top = false;
1136 }
1137 }
1138 draw_ladder(dest,x,y,COLOR_LADDER,top);
1139 }
1140 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1141 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1142 {
1143 draw_platform(dest,x,y,COLOR_LADDER);
1144 }
1145 }
1146
1147 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1148 {
1149 int32_t cx = COMBOX(pos);
1150 int32_t cy = COMBOY(pos);
1151
1152 if (screen < 0) return;
1153 if (map < 0) return;
1154
1155 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1156
1157 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1158
1159 int32_t bridgedetected = 0;
1160 for(int32_t i=0; i<4; i++)
1161 {
1162 int32_t tx=((i&2)<<2)+x;
1163 int32_t ty=((i&1)<<3)+y;
1164 int32_t tx2=((i&2)<<2)+cx;
1165 int32_t ty2=((i&1)<<3)+cy;
1166 for (int32_t m = layer; m <= 1; m++)
1167 {
1168 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1169 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1170 {
1171 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1172 {
1173 bridgedetected |= (1<<i);
1174 }
1175 }
1176 else
1177 {
1178 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1179 {
1180 bridgedetected |= (1<<i);
1181 }
1182 }
1183 }
1184 if (bridgedetected & (1<<i))
1185 {
1186 continue;
1187 }
1188 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1189 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1190
1191
1192 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1193 {
1194 for(int32_t k=0; k<8; k+=2)
1195 for(int32_t j=0; j<8; j+=2)
1196 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1197 }
1198 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1199 {
1200 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1201 {
1202 for(int32_t k=0; k<8; k+=2)
1203 for(int32_t j=0; j<8; j+=2)
1204 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1205 }
1206 else
1207 {
1208 int32_t color = COLOR_SOLID;
1209
1210 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1211 color=vc(6);
1212 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1213 color=vc(7);
1214
1215 rectfill(dest,tx,ty,tx+7,ty+7,color);
1216 }
1217 }
1218 }
1219
1220 bridgedetected = 0;
1221 for(int32_t i=0; i<4; i++)
1222 {
1223 int32_t tx2=((i&2)<<2)+cx;
1224 int32_t ty2=((i&1)<<3)+cy;
1225 for (int32_t m = 0; m <= 1; m++)
1226 {
1227 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1228 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1229 {
1230 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1231 {
1232 bridgedetected |= (1<<i);
1233 }
1234 }
1235 else
1236 {
1237 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1238 {
1239 bridgedetected |= (1<<i);
1240 }
1241 }
1242 }
1243 }
1244
1245 // Draw damage combos
1246 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1247 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1248 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1249 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1250 || combo_class_buf[c1.type].modify_hp_amount
1251 || combo_class_buf[c2.type].modify_hp_amount;
1252
1253 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1254
1255 if(dmg)
1256 {
1257 if (bridgedetected <= 0)
1258 {
1259 for(int32_t k=0; k<16; k+=2)
1260 for(int32_t j=0; j<16; j+=2)
1261 if(((k+j)/2)%2)
1262 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1263 }
1264 else
1265 {
1266 for(int32_t i=0; i<4; i++)
1267 {
1268 if (!(bridgedetected & (1<<i)))
1269 {
1270 int32_t tx=((i&2)<<2)+x;
1271 int32_t ty=((i&1)<<3)+y;
1272 for(int32_t k=0; k<8; k+=2)
1273 for(int32_t j=0; j<8; j+=2)
1274 if(((k+j)/2)%2)
1275 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1276 }
1277 }
1278 }
1279 }
1280
1281 if(c.type == cSLOPE)
1282 {
1283 slope_info s(c, x, y);
1284 s.draw(dest, 0, 0, COLOR_SLOPE);
1285 }
1286 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1287 auto fl1 = MAPFLAG3(map,screen,0,pos);
1288 auto fl2 = MAPFLAG3(map,screen,1,pos);
1289 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1290 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1291 {
1292 bool top = false;
1293 if(cy)
1294 {
1295 top = true;
1296 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1297 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1298 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1299 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1300 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1301 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1302 {
1303 top = false;
1304 }
1305 }
1306 draw_ladder(dest,x,y,COLOR_LADDER,top);
1307 }
1308 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1309 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1310 {
1311 draw_platform(dest,x,y,COLOR_LADDER);
1312 }
1313 }
1314
1315 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1316 {
1317 const newcombo& c = combobuf[cmbdat];
1318
1319 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1320
1321 for(int32_t i=0; i<4; i++)
1322 {
1323 int32_t tx=((i&2)<<2)+x;
1324 int32_t ty=((i&1)<<3)+y;
1325
1326 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1327 {
1328 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1329 {
1330 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1331 }
1332 else
1333 {
1334 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1335 }
1336 }
1337
1338
1339 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1340 {
1341 for(int32_t k=0; k<8; k+=2)
1342 for(int32_t j=0; j<8; j+=2)
1343 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1344 }
1345 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1346 {
1347 if(c.type==cLADDERHOOKSHOT)
1348 {
1349 for(int32_t k=0; k<8; k+=2)
1350 for(int32_t j=0; j<8; j+=2)
1351 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1352 }
1353 else
1354 {
1355 int32_t color = COLOR_SOLID;
1356
1357 if(c.type==cLADDERONLY)
1358 color=vc(6);
1359 else if(c.type==cHOOKSHOTONLY)
1360 color=vc(7);
1361
1362 rectfill(dest,tx,ty,tx+7,ty+7,color);
1363 }
1364 }
1365
1366 // Draw damage combos
1367 if(combo_class_buf[c.type].modify_hp_amount != 0)
1368 {
1369 for(int32_t k=0; k<8; k+=2)
1370 for(int32_t j=0; j<8; j+=2)
1371 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1372 }
1373 }
1374
1375 if(c.type == cSLOPE)
1376 {
1377 slope_info s(c, 0, 0);
1378 zfix const& slope = s.slope();
1379
1380 BITMAP* sub = create_bitmap_ex(8,16,16);
1381 clear_bitmap(sub);
1382 s.draw(sub, 0, 0, COLOR_SLOPE);
1383 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1384 destroy_bitmap(sub);
1385 }
1386 if(c.flag == mfSIDEVIEWLADDER)
1387 {
1388 draw_ladder(dest,x,y,COLOR_LADDER);
1389 }
1390 else if(c.flag == mfSIDEVIEWPLATFORM)
1391 {
1392 draw_platform(dest,x,y,COLOR_LADDER);
1393 }
1394 }
1395
1396 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1397 {
1398 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1399 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1400 }
1401 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1402 {
1403
1404 newcombo const& c = combobuf[cmbdat];
1405
1406 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1407 {
1408 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1409 // text_mode(-1);
1410 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1411 if(sflag)
1412 {
1413 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1414 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1415 }
1416
1417 if(c.flag)
1418 {
1419 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1420 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1421 }
1422 }
1423
1424 if(flags&cCSET)
1425 {
1426 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1427 // text_mode(inv?vc(15):vc(0));
1428 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1429 }
1430 else if(flags&cCTYPE)
1431 {
1432 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1433 // text_mode(inv?vc(15):vc(0));
1434 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1435 }
1436 }
1437
1438 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1439 {
1440 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1441
1442 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1443 if(repos)
1444 {
1445 combotile_override_x = x+(8*(scale-1));
1446 combotile_override_y = y+(8*(scale-1));
1447 }
1448 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1449 if(repos) combotile_override_x = combotile_override_y = -1;
1450 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1451 destroy_bitmap(b);
1452 }
1453 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1454 {
1455 static newcombo nilcombo;
1456 nilcombo.tile = 0;
1457
1458 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1459
1460 if(c.tile==0)
1461 {
1462 rectfill(dest,x,y,x+15,y+15,vc(0));
1463 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1464 return;
1465 }
1466
1467 putcombo(dest,x,y,cmbdat,cset);
1468
1469 /* moved to put_walkflags
1470 for(int32_t i=0; i<4; i++) {
1471
1472 int32_t tx=((i&2)<<2)+x;
1473 int32_t ty=((i&1)<<3)+y;
1474 if((flags&cWALK) && (c.walk&(1<<i)))
1475 rectfill(dest,tx,ty,tx+7,ty+7,COLOR_SOLID);
1476 }
1477 */
1478
1479 // if((flags&cFLAGS)&&(cmbdat&0xF800))
1480 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1481 {
1482 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1483 // text_mode(-1);
1484 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1485 if(sflag)
1486 {
1487 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1488 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1489 }
1490
1491 if(combobuf[cmbdat].flag)
1492 {
1493 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1494 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1495 }
1496 }
1497
1498 if(flags&cWALK)
1499 {
1500 put_walkflags(dest,x,y,cmbdat,0);
1501 }
1502
1503 if(flags&cCSET)
1504 {
1505 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1506 // text_mode(inv?vc(15):vc(0));
1507 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1508 }
1509 else if(flags&cCTYPE)
1510 {
1511 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1512 // text_mode(inv?vc(15):vc(0));
1513 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1514 }
1515 }
1516 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1517 {
1518 auto blitx = 1 + (slot % 16) * 17;
1519 auto blity = 1 + (slot / 16) * 17;
1520 masked_stretch_blit((BITMAP*)zcdata[BMP_ENGRAVINGS].dat, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1521 }
1522
1523
1524 void copy_mapscr(mapscr *dest, const mapscr *src)
1525 {
1526 if(!dest || !src) return;
1527 *dest = *src;
1528 }
1529
1530 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1531 {
1532 int32_t x=0,y=0;
1533 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1534
1535 switch(side)
1536 {
1537 case up:
1538 case down:
1539 x=((pos&15)<<4)+xofs;
1540 y=(ignorepos?0:(pos&0xF0))+yofs;
1541 break;
1542
1543 case left:
1544 case right:
1545 x=(ignorepos?0:((pos&15)<<4))+xofs;
1546 y=(pos&0xF0)+yofs;
1547 break;
1548 }
1549
1550 switch(type)
1551 {
1552 case dt_lock:
1553 case dt_shut:
1554 case dt_boss:
1555 case dt_bomb:
1556 switch(side)
1557 {
1558 case up:
1559 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1560 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1561 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1562 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1563 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1564 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1565 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1566 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1567 break;
1568
1569 case down:
1570 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1571 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1572 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1573 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1574 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1575 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1576 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1577 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1578 break;
1579
1580 case left:
1581 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1582 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1583 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1584 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1585 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1586 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1587
1588 if(x+16 >= dest->w)
1589 break;
1590
1591 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1592 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1593 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1594 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1595 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1596 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1597 break;
1598
1599 case right:
1600
1601 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1602 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1603 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1604 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1605 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1606 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1607
1608 if(x+16 <= 0)
1609 break;
1610
1611 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1612 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1613 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1614 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1615 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1616 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1617 break;
1618 }
1619
1620 break;
1621
1622 case dt_pass:
1623 case dt_wall:
1624 case dt_walk:
1625 default:
1626 break;
1627 }
1628 }
1629
1630 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1631 {
1632 int32_t x=((pos&15)<<4)+xofs;
1633 int32_t y=(pos&0xF0)+yofs;
1634 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1635
1636
1637 switch(side)
1638 {
1639 case up:
1640 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1641 {
1642 overcombo(dest,x,y,
1643 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1644 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1645 }
1646
1647 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1648 {
1649 overcombo(dest,x+16,y,
1650 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1651
1652 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1653 }
1654
1655 break;
1656
1657 case down:
1658 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1659 {
1660 overcombo(dest,x,y,
1661 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1662 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1663 }
1664
1665 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1666 {
1667 overcombo(dest,x+16,y,
1668 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1669 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1670 }
1671
1672 break;
1673
1674 case left:
1675 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1676 {
1677 overcombo(dest,x,y,
1678 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1679 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1680 }
1681
1682 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1683 {
1684 overcombo(dest,x,y+16,
1685 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1686 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1687 }
1688
1689 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1690 {
1691 overcombo(dest,x,y+32,
1692 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1693 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1694 }
1695
1696 break;
1697
1698 case right:
1699 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1700 {
1701 overcombo(dest,x,y,
1702 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1703 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1704 }
1705
1706 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1707 {
1708 overcombo(dest,x,y+16,
1709
1710 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1712 }
1713
1714 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1715 {
1716 overcombo(dest,x,y+32,
1717 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1718 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1719 }
1720
1721 break;
1722 }
1723 }
1724
1725 bool zmap::misaligned(int32_t map, int32_t scr, int32_t i, int32_t dir)
1726 {
1727 word cmbcheck1, cmbcheck2;
1728 newcombo combocheck1, combocheck2;
1729 combocheck1 = combobuf[0];
1730 combocheck2 = combobuf[0];
1731 combocheck1.walk = 0;
1732 combocheck2.walk = 0;
1733
1734 int32_t layermap, layerscreen;
1735
1736 switch(dir)
1737 {
1738 case up:
1739 {
1740 if(i>15) //not top row of combos
1741 {
1742 return false;
1743 }
1744
1745 if(scr<16) //top row of screens
1746 {
1747 return false;
1748
1749 }
1750
1751 //check main screen
1752 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1753 cmbcheck2 = vbound(AbsoluteScr(map, scr-16)->data[i+160], 0, MAXCOMBOS-1);
1754 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1755 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1756
1757 //check layer 1
1758 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1759
1760 if(layermap>-1 && layermap<map_count)
1761 {
1762 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1763 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1764 if (combobuf[cmbcheck1].type == cBRIDGE)
1765 {
1766 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1767 {
1768 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1769 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1770 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1771 }
1772 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1773 }
1774 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1775 }
1776
1777 layermap=AbsoluteScr(map, scr-16)->layermap[0]-1;
1778
1779 if(layermap>-1 && layermap<map_count)
1780 {
1781 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[0];
1782 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1783 if (combobuf[cmbcheck2].type == cBRIDGE)
1784 {
1785 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1786 {
1787 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1788 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1789 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1790 }
1791 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1792 }
1793 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1794 }
1795
1796 //check layer 2
1797 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1798
1799 if(layermap>-1 && layermap<map_count)
1800 {
1801 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1802
1803 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1804 if (combobuf[cmbcheck2].type == cBRIDGE)
1805 {
1806 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1807 {
1808 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1809 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1810 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1811 }
1812 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1813 }
1814 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1815 }
1816
1817 layermap=AbsoluteScr(map, scr-16)->layermap[1]-1;
1818
1819 if(layermap>-1 && layermap<map_count)
1820 {
1821 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[1];
1822 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1823 if (combobuf[cmbcheck2].type == cBRIDGE)
1824 {
1825 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1826 {
1827 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1828 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1829 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1830 }
1831 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1832 }
1833 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1834 }
1835
1836 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1837 {
1838 return true;
1839 }
1840
1841 break;
1842 }
1843 case down:
1844 {
1845 if(i<160) //not bottom row of combos
1846 {
1847 return false;
1848 }
1849
1850 if(scr>111) //bottom row of screens
1851 {
1852 return false;
1853 }
1854
1855 //check main screen
1856 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1857 cmbcheck2 = vbound(AbsoluteScr(map, scr+16)->data[i-160], 0, MAXCOMBOS-1);
1858 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1859 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1860
1861
1862 //check layer 1
1863 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1864
1865 if(layermap>-1 && layermap<map_count)
1866 {
1867 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1868 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1869 if (combobuf[cmbcheck1].type == cBRIDGE)
1870 {
1871 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1872 {
1873 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1874 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1875 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1876 }
1877 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1878 }
1879 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1880 }
1881
1882 layermap=AbsoluteScr(map, scr+16)->layermap[0]-1;
1883
1884 if(layermap>-1 && layermap<map_count)
1885 {
1886 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[0];
1887 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1888 if (combobuf[cmbcheck2].type == cBRIDGE)
1889 {
1890 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1891 {
1892 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1893 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1894 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1895 }
1896 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1897 }
1898 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1899 }
1900
1901 //check layer 2
1902 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1903
1904 if(layermap>-1 && layermap<map_count)
1905 {
1906 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1907 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1908 if (combobuf[cmbcheck1].type == cBRIDGE)
1909 {
1910 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1911 {
1912 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1913 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1914 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1915 }
1916 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1917 }
1918 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1919 }
1920
1921 layermap=AbsoluteScr(map, scr+16)->layermap[1]-1;
1922
1923 if(layermap>-1 && layermap<map_count)
1924 {
1925 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[1];
1926 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1927 if (combobuf[cmbcheck2].type == cBRIDGE)
1928 {
1929 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1930 {
1931 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1932 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1933 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1934 }
1935 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1936 }
1937 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1938 }
1939
1940 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
1941 {
1942 return true;
1943 }
1944
1945 break;
1946 }
1947 case left:
1948 {
1949 if((i&0xF)!=0) //not left column of combos
1950 {
1951 return false;
1952 }
1953
1954 if((scr&0xF)==0) //left column of screens
1955 {
1956 return false;
1957 }
1958
1959 //check main screen
1960 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
1961 cmbcheck2 = AbsoluteScr(map, scr-1)->data[i+15];
1962 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1963 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1964
1965 //check layer 1
1966 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1967
1968 if(layermap>-1 && layermap<map_count)
1969 {
1970 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1971 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1972 if (combobuf[cmbcheck1].type == cBRIDGE)
1973 {
1974 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1975 {
1976 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1977 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1978 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1979 }
1980 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1981 }
1982 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1983 }
1984
1985 layermap=AbsoluteScr(map, scr-1)->layermap[0]-1;
1986
1987 if(layermap>-1 && layermap<map_count)
1988 {
1989 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[0];
1990 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
1991 if (combobuf[cmbcheck2].type == cBRIDGE)
1992 {
1993 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1994 {
1995 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1996 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1997 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1998 }
1999 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2000 }
2001 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2002 }
2003
2004 //check layer 2
2005 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2006
2007 if(layermap>-1 && layermap<map_count)
2008 {
2009 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2010 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2011 if (combobuf[cmbcheck1].type == cBRIDGE)
2012 {
2013 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2014 {
2015 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2016 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2017 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2018 }
2019 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2020 }
2021 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2022 }
2023
2024 layermap=AbsoluteScr(map, scr-1)->layermap[1]-1;
2025
2026 if(layermap>-1 && layermap<map_count)
2027 {
2028 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[1];
2029 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2030 if (combobuf[cmbcheck2].type == cBRIDGE)
2031 {
2032 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2033 {
2034 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2035 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2036 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2037 }
2038 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2039 }
2040 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2041 }
2042
2043 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2044 {
2045 return true;
2046 }
2047
2048 break;
2049 }
2050 case right:
2051 {
2052 if((i&0xF)!=15) //not right column of combos
2053 {
2054 return false;
2055 }
2056
2057 if((scr&0xF)==15) //right column of screens
2058 {
2059 return false;
2060 }
2061
2062 //check main screen
2063 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2064 cmbcheck2 = AbsoluteScr(map, scr+1)->data[i-15];
2065 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2066 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2067
2068 //check layer 1
2069 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2070
2071 if(layermap>-1 && layermap<map_count)
2072 {
2073 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2074 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2075 if (combobuf[cmbcheck1].type == cBRIDGE)
2076 {
2077 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2078 {
2079 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2080 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2081 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2082 }
2083 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2084 }
2085 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2086 }
2087
2088 layermap=AbsoluteScr(map, scr+1)->layermap[0]-1;
2089
2090 if(layermap>-1 && layermap<map_count)
2091 {
2092 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[0];
2093 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2094 if (combobuf[cmbcheck2].type == cBRIDGE)
2095 {
2096 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2097 {
2098 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2099 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2100 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2101 }
2102 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2103 }
2104 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2105 }
2106
2107 //check layer 2
2108 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2109
2110 if(layermap>-1 && layermap<map_count)
2111 {
2112 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2113 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2114 if (combobuf[cmbcheck1].type == cBRIDGE)
2115 {
2116 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2117 {
2118 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2119 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2120 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2121 }
2122 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2123 }
2124 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2125 }
2126
2127 layermap=AbsoluteScr(map, scr+1)->layermap[1]-1;
2128
2129 if(layermap>-1 && layermap<map_count)
2130 {
2131 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[1];
2132
2133 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2134 if (combobuf[cmbcheck2].type == cBRIDGE)
2135 {
2136 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2137 {
2138 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2139 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2140 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2141 }
2142 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2143 }
2144 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2145 }
2146
2147 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2148 {
2149 return true;
2150 }
2151
2152 break;
2153 }
2154 }
2155
2156 return false;
2157 }
2158
2159 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2160 {
2161 int32_t checkcombo;
2162
2163 if(alignment_arrow_timer>31)
2164 {
2165 if(scr<0)
2166 {
2167 scr=currscr;
2168 }
2169
2170 if((scr<128)) //do the misalignment arrows
2171 {
2172 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2173 {
2174 if(misaligned(currmap, scr, checkcombo, up))
2175 {
2176 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2177 }
2178 }
2179
2180 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2181 {
2182 if(misaligned(currmap, scr, checkcombo, down))
2183 {
2184 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2185 }
2186 }
2187
2188 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2189 {
2190 if(misaligned(currmap, scr, checkcombo, left))
2191 {
2192 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2193 }
2194 }
2195
2196 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2197 {
2198 if(misaligned(currmap, scr, checkcombo, right))
2199 {
2200 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2201 }
2202 }
2203
2204 int32_t tempalign;
2205
2206 //check top left corner
2207 checkcombo=0;
2208 tempalign=0;
2209 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2210 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2211
2212 switch(tempalign)
2213 {
2214 case 0:
2215 break;
2216
2217 case 1: //up
2218 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2219 break;
2220
2221 case 2: //left
2222 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2223 break;
2224
2225 case 3: //up-left
2226 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2227 break;
2228 }
2229
2230 //check top right corner
2231 checkcombo=15;
2232 tempalign=0;
2233 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2234 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2235
2236 switch(tempalign)
2237 {
2238 case 0:
2239 break;
2240
2241 case 1: //up
2242 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2243 break;
2244
2245 case 2: //right
2246 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2247 break;
2248
2249 case 3: //up-right
2250 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2251 break;
2252 }
2253
2254 //check bottom left corner
2255 checkcombo=160;
2256 tempalign=0;
2257 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2258 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2259
2260 switch(tempalign)
2261 {
2262 case 0:
2263 break;
2264
2265 case 1: //down
2266 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2267 break;
2268
2269 case 2: //left
2270 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2271 break;
2272
2273 case 3: //down-left
2274 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2275 break;
2276 }
2277
2278 //check bottom right corner
2279
2280 checkcombo=175;
2281 tempalign=0;
2282 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2283 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2284
2285 switch(tempalign)
2286 {
2287 case 0:
2288 break;
2289
2290 case 1: //down
2291 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2292 break;
2293
2294 case 2: //right
2295 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2296 break;
2297
2298 case 3: //down-right
2299 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2300 break;
2301 }
2302 }
2303 }
2304 }
2305
2306 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2307 {
2308 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2309 }
2310
2311 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2312 {
2313 if (map < 0 || screen < 0) return 0;
2314
2315 if(pos>175 || pos < 0)
2316 return 0;
2317
2318 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2319
2320 if(m->valid==0) return 0;
2321
2322 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2323
2324 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2325
2326 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2327
2328 if(scr->valid==0) return 0;
2329
2330 return scr->data[pos]; // entire combo code
2331 }
2332
2333 // Takes array index layer num., not actual layer num.
2334 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2335 {
2336 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2337
2338 if(map<0)
2339 map=currmap;
2340
2341 if(scr<0)
2342 scr=currscr;
2343
2344 mapscr *screen1;
2345
2346 if(prv_mode)
2347 {
2348 screen1=get_prvscr();
2349 }
2350 else
2351 {
2352 screen1=AbsoluteScr(currmap,currscr);
2353 }
2354
2355 int32_t layermap;
2356 layermap=screen1->layermap[lyr]-1;
2357
2358 if(layermap<0 || layermap >= map_count) return 0;
2359
2360 mapscr *layer;
2361
2362 if(prv_mode)
2363 layer = &prvlayers[lyr];
2364 else
2365 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2366
2367 int32_t combo = COMBOPOS(x,y);
2368
2369 if(combo>175 || combo < 0)
2370 return 0;
2371
2372 return layer->data[combo];
2373 }
2374
2375 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2376 {
2377 if(map<0)
2378 map=currmap;
2379
2380 if(scr<0)
2381 scr=currscr;
2382
2383 mapscr *screen1;
2384
2385 if(prv_mode)
2386 {
2387 screen1=get_prvscr();
2388 }
2389 else
2390 {
2391 screen1=AbsoluteScr(currmap,currscr);
2392 }
2393
2394 x = vbound(x, 0, 16*16);
2395 y = vbound(y, 0, 11*16);
2396 int32_t combo = COMBOPOS(x,y);
2397
2398 if(combo>175 || combo < 0)
2399 return 0;
2400
2401 return screen1->data[combo];
2402 }
2403
2404 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2405 {
2406 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2407 }
2408
2409 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2410 {
2411 if (map < 0 || screen < 0) return 0;
2412
2413 if(pos>175 || pos < 0)
2414 return 0;
2415
2416 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2417
2418 if(m->valid==0) return 0;
2419
2420 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2421
2422 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2423
2424 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2425
2426 if(scr->valid==0) return 0;
2427
2428 return scr->sflag[pos]; // entire combo code
2429 }
2430
2431 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2432 {
2433 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2434
2435 if(map<0)
2436 map=currmap;
2437
2438 if(scr<0)
2439 scr=currscr;
2440
2441 mapscr *screen1;
2442
2443 if(prv_mode)
2444 {
2445 screen1=get_prvscr();
2446 }
2447 else
2448 {
2449 screen1=AbsoluteScr(currmap,currscr);
2450 }
2451
2452 int32_t layermap;
2453 layermap=screen1->layermap[lyr]-1;
2454
2455 if(layermap<0 || layermap >= map_count) return 0;
2456
2457 mapscr *layer;
2458
2459 if(prv_mode)
2460 layer = &prvlayers[lyr];
2461 else
2462 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2463
2464 int32_t combo = COMBOPOS(x,y);
2465
2466 if(combo>175 || combo < 0)
2467 return 0;
2468
2469 return layer->sflag[combo];
2470 }
2471
2472 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2473 {
2474 if(map<0)
2475 map=currmap;
2476
2477 if(scr<0)
2478 scr=currscr;
2479
2480 mapscr *screen1;
2481
2482 if(prv_mode)
2483 {
2484 screen1=get_prvscr();
2485 }
2486 else
2487 {
2488 screen1=AbsoluteScr(currmap,currscr);
2489 }
2490
2491 x = vbound(x, 0, 16*16);
2492 y = vbound(y, 0, 11*16);
2493 int32_t combo = COMBOPOS(x,y);
2494
2495 if(combo>175 || combo < 0)
2496 return 0;
2497
2498 return screen1->sflag[combo];
2499 }
2500
2501 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2502 {
2503 mapscr *layers[7];
2504 mapscr *basescr;
2505 if(prv_mode)
2506 {
2507 layers[0] = &prvscr;
2508 basescr = layers[0];
2509 for(auto q = 1; q < 7; ++q)
2510 {
2511 if(prvlayers[q-1].valid)
2512 layers[q] = &(prvlayers[q-1]);
2513 else layers[q] = NULL;
2514 }
2515 }
2516 else
2517 {
2518 layers[0] = AbsoluteScr(currmap, currscr);
2519 basescr = layers[0];
2520 for(auto q = 1; q < 7; ++q)
2521 {
2522 int32_t lmap = basescr->layermap[q-1]-1;
2523 int32_t lscr = basescr->layerscreen[q-1];
2524 if(lmap < 0)
2525 layers[q] = NULL;
2526 else layers[q] = AbsoluteScr(lmap, lscr);
2527 }
2528 }
2529 for(auto q = 0; q < 7; ++q)
2530 {
2531 if(!layers[q]) continue;
2532 for(auto pos = 0; pos < 176; ++pos)
2533 {
2534 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2535 if(cmb.type == cTORCH)
2536 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2537 }
2538 }
2539 word maxffc = basescr->numFFC();
2540 for(auto q = 0; q < maxffc; ++q)
2541 {
2542 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2543 if(cmb.type == cTORCH)
2544 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2545 }
2546 }
2547
2548 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2549 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2550 {
2551 newcombo const& cmb = combobuf[cid];
2552 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2553 if(dither)
2554 {
2555 if (LayerDitherSz == 0)
2556 return;
2557 BITMAP* buf = create_bitmap_ex(8,16,16);
2558 clear_bitmap(buf);
2559 overcombo(buf,0,0,cid,cset);
2560 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2561 if(over)
2562 {
2563 if(transp)
2564 {
2565 color_map = &trans_table2;
2566 draw_trans_sprite(dest, buf, x, y);
2567 color_map = &trans_table;
2568 }
2569 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2570 }
2571 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2572 destroy_bitmap(buf);
2573 }
2574 else if(over)
2575 {
2576 if(transp)
2577 overcombotranslucent(dest,x,y,cid,cset,0);
2578 else overcombo(dest,x,y,cid,cset);
2579 }
2580 else put_combo(dest,x,y,cid,cset,flags,sflag);
2581 }
2582 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2583 {
2584 if(!md) return;
2585 for (int32_t i = 0; i < 176; i++)
2586 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2587 }
2588 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2589 {
2590 if(!md) return;
2591 for (int32_t i = 0; i < 176; i++)
2592 {
2593 int data = md->data[i];
2594 if(combo_class_buf[combobuf[data].type].overhead)
2595 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2596 }
2597 }
2598 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2599 {
2600 if(!LayerMaskInt[lyr])
2601 return nullptr;
2602 if(lyr == 0)
2603 return basescr;
2604 int layermap = basescr->layermap[lyr-1]-1;
2605
2606 if(layermap>-1 && layermap<map_count)
2607 {
2608 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2609 return &TheMaps[layerscreen];
2610 }
2611 return nullptr;
2612 }
2613 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t scr,int32_t hl_layer)
2614 {
2615 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2616 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2617
2618 if(map<0)
2619 map=currmap;
2620
2621 if(scr<0)
2622 scr=currscr;
2623
2624 mapscr *basescr;
2625 mapscr* layers[7] = {nullptr};
2626
2627 if(prv_mode)
2628 {
2629 hl_layer = -1;
2630 basescr=get_prvscr();
2631 }
2632 else
2633 {
2634 basescr=AbsoluteScr(map,scr);
2635 }
2636 layers[0] = _zmap_get_lyr_checked(0,basescr);
2637 for(int lyr = 1; lyr < 7; ++lyr)
2638 {
2639 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2640 : _zmap_get_lyr_checked(lyr,basescr);
2641 }
2642
2643 int32_t layermap, layerscreen;
2644 if(CurrentLayer < 1)
2645 layermap = -1;
2646 else
2647 {
2648 layermap=basescr->layermap[CurrentLayer-1]-1;
2649
2650 if(layermap<0)
2651 CurrentLayer=0;
2652 }
2653
2654 if(!(basescr->valid&mVALID))
2655 {
2656 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2657 rectfill(dest,x,y,x+255,y+175,vc(1));
2658
2659 if(ShowMisalignments)
2660 {
2661 check_alignments(dest,x,y,scr);
2662 }
2663
2664 return;
2665 }
2666
2667 if(LayerMaskInt[0]==0)
2668 {
2669 byte bgfill = 0;
2670 if (LayerDitherBG > -1)
2671 bgfill = vc(LayerDitherBG);
2672 rectfill(dest,x,y,x+255,y+175,bgfill);
2673 }
2674
2675 resize_mouse_pos=true;
2676 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2677 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2678
2679 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2680 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2681
2682 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2683
2684 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2685
2686 for(int32_t i=MAXFFCS-1; i>=0; i--)
2687 {
2688 if(basescr->ffcs[i].data)
2689 {
2690 if(!(basescr->ffcs[i].flags&ffc_changer))
2691 {
2692 if(!(basescr->ffcs[i].flags&ffc_overlay))
2693 {
2694 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2695 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2696
2697 if(basescr->ffcs[i].flags&ffc_trans)
2698 {
2699 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2700 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2701 }
2702 else
2703 {
2704 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2705 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2706 }
2707 }
2708 }
2709 }
2710 }
2711
2712 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2713 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2714
2715 int32_t doortype[4];
2716
2717 for(int32_t i=0; i<4; i++)
2718 {
2719 switch(basescr->door[i])
2720 {
2721 case dOPEN:
2722 doortype[i]=dt_pass;
2723 break;
2724
2725 case dLOCKED:
2726 doortype[i]=dt_lock;
2727 break;
2728
2729 case d1WAYSHUTTER:
2730 case dSHUTTER:
2731 doortype[i]=dt_shut;
2732 break;
2733
2734 case dBOSS:
2735 doortype[i]=dt_boss;
2736 break;
2737
2738 case dBOMB:
2739 doortype[i]=dt_bomb;
2740 break;
2741 }
2742 }
2743
2744 switch(basescr->door[up])
2745 {
2746 case dBOMB:
2747 over_door(dest,39,up,x,y,false, scr);
2748 [[fallthrough]];
2749 case dOPEN:
2750 case dLOCKED:
2751 case d1WAYSHUTTER:
2752 case dSHUTTER:
2753 case dBOSS:
2754 put_door(dest,7,up,doortype[up],x,y,false,scr);
2755 break;
2756
2757 case dWALK:
2758 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2759 {
2760 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2761 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2762 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0]);
2763 }
2764 else
2765
2766 {
2767 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2768 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2769 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0],0,0);
2770 }
2771
2772 break;
2773 }
2774
2775 switch(basescr->door[down])
2776 {
2777 case dBOMB:
2778 over_door(dest,135,down,x,y,false,scr);
2779 [[fallthrough]];
2780 case dOPEN:
2781 case dLOCKED:
2782 case d1WAYSHUTTER:
2783 case dSHUTTER:
2784 case dBOSS:
2785 put_door(dest,151,down,doortype[down],x,y,false,scr);
2786 break;
2787
2788 case dWALK:
2789 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2790 {
2791 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2792 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2793 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1]);
2794 }
2795 else
2796 {
2797 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2798 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2799 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1],0,0);
2800 }
2801
2802 break;
2803 }
2804
2805 switch(basescr->door[left])
2806 {
2807 case dBOMB:
2808 over_door(dest,66,left,x,y,false,scr);
2809 [[fallthrough]];
2810 case dOPEN:
2811 case dLOCKED:
2812 case d1WAYSHUTTER:
2813 case dSHUTTER:
2814 case dBOSS:
2815 put_door(dest,64,left,doortype[left],x,y,false,scr);
2816 break;
2817
2818 case dWALK:
2819 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2820 {
2821 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2822 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2823 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2]);
2824 }
2825 else
2826 {
2827 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2828 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2829 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2],0,0);
2830 }
2831
2832 break;
2833 }
2834
2835 switch(basescr->door[right])
2836 {
2837
2838 case dBOMB:
2839 over_door(dest,77,right,x,y,false,scr);
2840 [[fallthrough]];
2841 case dOPEN:
2842 case dLOCKED:
2843 case d1WAYSHUTTER:
2844 case dSHUTTER:
2845 case dBOSS:
2846 put_door(dest,78,right,doortype[right],x,y,false,scr);
2847 break;
2848
2849 case dWALK:
2850 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2851 {
2852 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2853 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2854 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3]);
2855 }
2856 else
2857 {
2858 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2859 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2860 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3],0,0);
2861 }
2862
2863 break;
2864 }
2865
2866 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2867 {
2868 frame=0;
2869 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2870 }
2871
2872 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2873 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2874 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2875
2876 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2877
2878 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2879 {
2880 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2881 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2882 }
2883 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2884
2885 for(int32_t i=MAXFFCS-1; i>=0; i--)
2886 {
2887 if(basescr->ffcs[i].data)
2888 {
2889 if(!(basescr->ffcs[i].flags&ffc_changer))
2890 {
2891 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2892 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2893
2894 if(basescr->ffcs[i].flags&ffc_overlay)
2895 {
2896 if(basescr->ffcs[i].flags&ffc_trans)
2897 {
2898 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2899 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2900 }
2901 else
2902 {
2903 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2904 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2905 }
2906 }
2907 }
2908 }
2909 }
2910
2911 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2912
2913 for(int32_t i=MAXFFCS-1; i>=0; i--)
2914 if(basescr->ffcs[i].data)
2915 if(basescr->ffcs[i].flags&ffc_changer)
2916 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2917
2918 if(flags&cWALK)
2919 {
2920 if(layers[0])
2921 for(int32_t i=0; i<176; i++)
2922 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2923
2924 for(int32_t k=0; k<2; k++)
2925 {
2926 if(layers[k+1])
2927 for(int32_t i=0; i<176; i++)
2928 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2929 }
2930 for(int32_t i=MAXFFCS-1; i>=0; i--)
2931 {
2932 if(auto data = basescr->ffcs[i].data)
2933 {
2934 if(!(basescr->ffcs[i].flags&ffc_changer))
2935 {
2936 newcombo const& cmb = combobuf[data];
2937 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2938 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2939
2940 if(basescr->ffcs[i].flags&ffc_solid)
2941 {
2942 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2943 }
2944
2945 if(cmb.type == cSLOPE)
2946 {
2947 slope_info s(cmb, tx, ty);
2948 s.draw(dest, 0, 0, COLOR_SLOPE);
2949 }
2950 }
2951 }
2952 }
2953 }
2954
2955 if(flags&cFLAGS)
2956 {
2957 if(LayerMaskInt[CurrentLayer]!=0)
2958 {
2959 for(int32_t i=0; i<176; i++)
2960 {
2961 if(CurrentLayer==0)
2962 {
2963 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2964 }
2965 else
2966 {
2967 if(prv_mode)
2968 {
2969 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2970 }
2971 else
2972 {
2973 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2974
2975 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
2976 {
2977 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2978 TheMaps[_lscr].data[i],
2979 TheMaps[_lscr].cset[i], flags,
2980 TheMaps[_lscr].sflag[i]);
2981 }
2982 }
2983 }
2984 }
2985 }
2986 }
2987
2988 int32_t dark = basescr->flags&cDARK;
2989
2990 if(dark && !(flags&cNODARK)
2991 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2992 {
2993 for(int32_t j=0; j<80; j++)
2994 {
2995 for(int32_t i=0; i<(80)-j; i++)
2996 {
2997 if(((i^j)&1)==0)
2998 {
2999 putpixel(dest,x+i,y+j,vc(blackout_color));
3000 }
3001 }
3002 }
3003 }
3004
3005 if(ShowMisalignments)
3006 {
3007 check_alignments(dest,x,y,scr);
3008 }
3009
3010 resize_mouse_pos=false;
3011 }
3012
3013 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3014 {
3015 if(map<0)
3016 map=currmap;
3017
3018 if(scr<0)
3019 scr=currscr;
3020
3021 mapscr* layer=AbsoluteScr(map,scr);
3022 int32_t layermap=0, layerscreen=0;
3023
3024 if(!(layer->valid&mVALID))
3025 {
3026 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3027 rectfill(dest,x,y,x+255,y+15,vc(1));
3028 return;
3029 }
3030
3031 int32_t dark = layer->flags&4;
3032
3033 resize_mouse_pos=true;
3034
3035 if(LayerMaskInt[0]==0)
3036 {
3037 rectfill(dest,x,y,x+255,y+15,0);
3038 }
3039
3040
3041 for(int32_t k=1; k<3; k++)
3042 {
3043 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3044 {
3045 layermap=layer->layermap[k]-1;
3046
3047 if(layermap>-1 && layermap<map_count)
3048 {
3049 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3050
3051 for(int32_t i=c; i<(c&0xF0)+16; i++)
3052 {
3053 auto data = TheMaps[layerscreen].data[i];
3054 auto cs = TheMaps[layerscreen].cset[i];
3055 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3056 }
3057 }
3058 }
3059 }
3060
3061 if(LayerMaskInt[0]!=0)
3062 {
3063 for(int32_t i=c; i<(c&0xF0)+16; i++)
3064 {
3065 word cmbdat = (i < 176 ? layer->data[i] : 0);
3066 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3067 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3068 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3069 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3070 }
3071 }
3072
3073 for(int32_t k=0; k<2; k++)
3074 {
3075 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3076 {
3077 layermap=layer->layermap[k]-1;
3078
3079 if(layermap>-1 && layermap<map_count)
3080 {
3081 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3082
3083 for(int32_t i=c; i<(c&0xF0)+16; i++)
3084 {
3085 auto data = TheMaps[layerscreen].data[i];
3086 auto cs = TheMaps[layerscreen].cset[i];
3087 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3088 }
3089 }
3090 }
3091 }
3092
3093 int32_t doortype[4];
3094
3095 for(int32_t i=0; i<4; i++)
3096 {
3097 switch(layer->door[i])
3098 {
3099 case dOPEN:
3100 doortype[i]=dt_pass;
3101 break;
3102
3103 case dLOCKED:
3104 doortype[i]=dt_lock;
3105 break;
3106
3107 case d1WAYSHUTTER:
3108 case dSHUTTER:
3109 doortype[i]=dt_shut;
3110 break;
3111
3112 case dBOSS:
3113 doortype[i]=dt_boss;
3114 break;
3115
3116 case dBOMB:
3117 doortype[i]=dt_bomb;
3118 break;
3119 }
3120 }
3121
3122 if(c<16)
3123 {
3124 switch(layer->door[up])
3125 {
3126 case dBOMB:
3127 case dOPEN:
3128 case dLOCKED:
3129 case d1WAYSHUTTER:
3130 case dSHUTTER:
3131 case dBOSS:
3132 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3133 break;
3134 }
3135 }
3136 else if(c>159)
3137 {
3138 switch(layer->door[down])
3139 {
3140 case dBOMB:
3141 case dOPEN:
3142 case dLOCKED:
3143 case d1WAYSHUTTER:
3144 case dSHUTTER:
3145 case dBOSS:
3146 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3147 break;
3148 }
3149 }
3150
3151 for(int32_t k=2; k<4; k++)
3152 {
3153 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3154 {
3155 layermap=layer->layermap[k]-1;
3156
3157 if(layermap>-1 && layermap<map_count)
3158 {
3159 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3160
3161 for(int32_t i=c; i<(c&0xF0)+16; i++)
3162 {
3163 if(layer->layeropacity[k]<255)
3164 {
3165 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3166 }
3167 else
3168 {
3169 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3170 }
3171 }
3172 }
3173 }
3174 }
3175
3176 //Overhead L0
3177 if(LayerMaskInt[0]!=0)
3178 {
3179 for(int32_t i=c; i<(c&0xF0)+16; i++)
3180 {
3181 int32_t ct1=layer->data[i];
3182 int32_t ct3=combobuf[ct1].type;
3183
3184 if(combo_class_buf[ct3].overhead)
3185 {
3186 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3187 }
3188 }
3189 }
3190
3191 //Overhead L1/2
3192 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3193 {
3194 for(int32_t k = 0; k < 2; ++k)
3195 {
3196 if(LayerMaskInt[k+1]!=0)
3197 {
3198 layermap=layer->layermap[k]-1;
3199
3200 if(layermap>-1 && layermap<map_count)
3201 {
3202 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3203 for(int32_t i=c; i<(c&0xF0)+16; i++)
3204 {
3205 auto data = TheMaps[layerscreen].data[i];
3206 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3207 auto cs = TheMaps[layerscreen].cset[i];
3208 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3209 }
3210 }
3211 }
3212 }
3213 }
3214
3215 for(int32_t k=4; k<6; k++)
3216 {
3217 if(LayerMaskInt[k+1]!=0)
3218 {
3219 layermap=layer->layermap[k]-1;
3220
3221 if(layermap>-1 && layermap<map_count)
3222 {
3223 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3224
3225 for(int32_t i=c; i<(c&0xF0)+16; i++)
3226 {
3227 auto data = TheMaps[layerscreen].data[i];
3228 auto cs = TheMaps[layerscreen].cset[i];
3229 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3230 }
3231 }
3232 }
3233 }
3234
3235 if(flags&cWALK)
3236 {
3237 if(LayerMaskInt[0]!=0)
3238 {
3239 for(int32_t i=c; i<(c&0xF0)+16; i++)
3240 {
3241 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3242 }
3243 }
3244
3245 for(int32_t k=0; k<2; k++)
3246 {
3247 if(LayerMaskInt[k+1]!=0)
3248 {
3249 for(int32_t i=c; i<(c&0xF0)+16; i++)
3250 {
3251 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3252 }
3253 }
3254 }
3255 }
3256
3257 if(flags&cFLAGS)
3258 {
3259 if(LayerMaskInt[CurrentLayer]!=0)
3260 {
3261 for(int32_t i=c; i<(c&0xF0)+16; i++)
3262 {
3263 if(CurrentLayer==0)
3264 {
3265 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3266 }
3267 else
3268 {
3269 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3270
3271 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3272 {
3273 if(i < 176)
3274 {
3275 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3276 TheMaps[_lscr].data[i],
3277 TheMaps[_lscr].cset[i], flags|dark,
3278 TheMaps[_lscr].sflag[i]);
3279 }
3280 else
3281 {
3282 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3283 }
3284 }
3285 }
3286 }
3287 }
3288
3289 /*
3290 if (LayerMaskInt[0]!=0) {
3291 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3292 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3293 }
3294 }
3295 */
3296 }
3297
3298 if(ShowMisalignments)
3299 {
3300 if(c<16)
3301 {
3302 check_alignments(dest,x,y,scr);
3303 }
3304 else if(c>159)
3305 {
3306 check_alignments(dest,x,y-160,scr);
3307 }
3308 }
3309
3310 resize_mouse_pos=false;
3311
3312 }
3313
3314 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3315 {
3316 if(map<0)
3317 map=currmap;
3318
3319 if(scr<0)
3320 scr=currscr;
3321
3322 mapscr* layer=AbsoluteScr(map,scr);
3323 int32_t layermap=0, layerscreen=0;
3324
3325 if(!(layer->valid&mVALID))
3326 {
3327 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3328 rectfill(dest,x,y,x+15,y+175,vc(1));
3329 return;
3330 }
3331
3332 int32_t dark = layer->flags&4;
3333
3334 resize_mouse_pos=true;
3335
3336
3337 if(LayerMaskInt[0]==0)
3338 {
3339 rectfill(dest,x,y,x+15,y+175,0);
3340 }
3341
3342
3343 for(int32_t k=1; k<3; k++)
3344 {
3345 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3346 {
3347 layermap=layer->layermap[k]-1;
3348
3349 if(layermap>-1 && layermap<map_count)
3350 {
3351 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3352
3353 for(int32_t i=c; i<176; i+=16)
3354 {
3355 auto data = TheMaps[layerscreen].data[i];
3356 auto cs = TheMaps[layerscreen].cset[i];
3357 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3358 }
3359 }
3360 }
3361 }
3362
3363 if(LayerMaskInt[0]!=0)
3364 {
3365 for(int32_t i=c; i<176; i+=16)
3366 {
3367 word cmbdat = layer->data[i];
3368 byte cmbcset = layer->cset[i];
3369 int32_t cmbflag = layer->sflag[i];
3370 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3371 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3372 }
3373 }
3374
3375 for(int32_t k=0; k<2; k++)
3376 {
3377 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3378 {
3379 layermap=layer->layermap[k]-1;
3380
3381 if(layermap>-1 && layermap<map_count)
3382 {
3383 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3384
3385 for(int32_t i=c; i<176; i+=16)
3386 {
3387 auto data = TheMaps[layerscreen].data[i];
3388 auto cs = TheMaps[layerscreen].cset[i];
3389 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3390 }
3391 }
3392 }
3393 }
3394
3395 int32_t doortype[4];
3396
3397 for(int32_t i=0; i<4; i++)
3398 {
3399 switch(layer->door[i])
3400 {
3401 case dOPEN:
3402 doortype[i]=dt_pass;
3403 break;
3404
3405 case dLOCKED:
3406 doortype[i]=dt_lock;
3407 break;
3408
3409 case d1WAYSHUTTER:
3410 case dSHUTTER:
3411 doortype[i]=dt_shut;
3412 break;
3413
3414 case dBOSS:
3415 doortype[i]=dt_boss;
3416 break;
3417
3418 case dBOMB:
3419 doortype[i]=dt_bomb;
3420 break;
3421 }
3422 }
3423
3424 if((c&0x0F)==0)
3425 {
3426 switch(layer->door[left])
3427 {
3428
3429 case dBOMB:
3430 case dOPEN:
3431 case dLOCKED:
3432 case d1WAYSHUTTER:
3433 case dSHUTTER:
3434 case dBOSS:
3435 // put_door(dest,64,left,doortype[left],x+256,y,true);
3436 put_door(dest,64,left,doortype[left],x,y,true,scr);
3437 break;
3438 }
3439 }
3440 else if((c&0x0F)==15)
3441 {
3442 switch(layer->door[right])
3443 {
3444 case dBOMB:
3445 case dOPEN:
3446 case dLOCKED:
3447 case d1WAYSHUTTER:
3448 case dSHUTTER:
3449 case dBOSS:
3450 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3451 break;
3452 }
3453 }
3454
3455 for(int32_t k=2; k<4; k++)
3456 {
3457 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3458 {
3459 layermap=layer->layermap[k]-1;
3460
3461 if(layermap>-1 && layermap<map_count)
3462 {
3463 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3464
3465 for(int32_t i=c; i<176; i+=16)
3466 {
3467 auto data = TheMaps[layerscreen].data[i];
3468 auto cs = TheMaps[layerscreen].cset[i];
3469 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3470 }
3471 }
3472 }
3473 }
3474
3475 //Overhead L0
3476 if(LayerMaskInt[0]!=0)
3477 {
3478 for(int32_t i=c; i<176; i+=16)
3479 {
3480 auto data = TheMaps[layerscreen].data[i];
3481 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3482 auto cs = TheMaps[layerscreen].cset[i];
3483 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3484 }
3485 }
3486 //Overhead L1/2
3487 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3488 {
3489 for(int32_t k = 0; k < 2; ++k)
3490 {
3491 if(LayerMaskInt[k+1]!=0)
3492 {
3493 layermap=layer->layermap[k]-1;
3494
3495 if(layermap>-1 && layermap<map_count)
3496 {
3497 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3498 for(int32_t i=c; i<176; i+=16)
3499 {
3500 auto data = TheMaps[layerscreen].data[i];
3501 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3502 auto cs = TheMaps[layerscreen].cset[i];
3503 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3504 }
3505 }
3506 }
3507 }
3508 }
3509
3510
3511 for(int32_t k=4; k<6; k++)
3512 {
3513 if(LayerMaskInt[k+1]!=0)
3514 {
3515 layermap=layer->layermap[k]-1;
3516
3517 if(layermap>-1 && layermap<map_count)
3518 {
3519 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3520
3521 for(int32_t i=c; i<176; i+=16)
3522 {
3523 auto data = TheMaps[layerscreen].data[i];
3524 auto cs = TheMaps[layerscreen].cset[i];
3525 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3526 }
3527 }
3528 }
3529 }
3530
3531 if(flags&cWALK)
3532 {
3533 if(LayerMaskInt[0]!=0)
3534 {
3535 for(int32_t i=c&0xF; i<176; i+=16)
3536 {
3537 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3538 }
3539 }
3540
3541 for(int32_t k=0; k<2; k++)
3542 {
3543 if(LayerMaskInt[k+1]!=0)
3544 {
3545 for(int32_t i=c&0xF; i<176; i+=16)
3546 {
3547 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3548 }
3549 }
3550 }
3551 }
3552
3553 if(flags&cFLAGS)
3554 {
3555 if(LayerMaskInt[CurrentLayer]!=0)
3556 {
3557 for(int32_t i=c; i<176; i+=16)
3558 {
3559 if(CurrentLayer==0)
3560 {
3561 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3562 }
3563 else
3564 {
3565 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3566
3567 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3568 {
3569 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3570 TheMaps[_lscr].data[i],
3571 TheMaps[_lscr].cset[i], flags|dark,
3572 TheMaps[_lscr].sflag[i]);
3573 }
3574 }
3575 }
3576 }
3577 }
3578
3579 if(ShowMisalignments)
3580 {
3581 if((c&0x0F)==0)
3582 {
3583 check_alignments(dest,x,y,scr);
3584 }
3585 else if((c&0x0F)==15)
3586 {
3587 check_alignments(dest,x-240,y,scr);
3588 }
3589 }
3590
3591 resize_mouse_pos=false;
3592 }
3593
3594 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3595 {
3596 if(map<0)
3597 map=currmap;
3598
3599 if(scr<0)
3600 scr=currscr;
3601
3602 mapscr* layer=AbsoluteScr(map,scr);
3603 int32_t layermap=0, layerscreen=0;
3604
3605 if(!(layer->valid&mVALID))
3606 {
3607 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3608 rectfill(dest,x,y,x+15,y+15,vc(1));
3609 return;
3610 }
3611
3612 int32_t dark = layer->flags&4;
3613
3614 resize_mouse_pos=true;
3615
3616 if(LayerMaskInt[0]!=0)
3617 {
3618 rectfill(dest,x,y,x+15,y+15,0);
3619 }
3620
3621 for(int32_t k=1; k<3; k++)
3622 {
3623 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3624 {
3625 layermap=layer->layermap[k]-1;
3626
3627 if(layermap>-1 && layermap<map_count)
3628 {
3629 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3630
3631 auto data = TheMaps[layerscreen].data[c];
3632 auto cs = TheMaps[layerscreen].cset[c];
3633 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3634 }
3635 }
3636 }
3637
3638 if(LayerMaskInt[0]!=0)
3639 {
3640 word cmbdat = layer->data[c];
3641 byte cmbcset = layer->cset[c];
3642 int32_t cmbflag = layer->sflag[c];
3643 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3644 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3645 }
3646
3647
3648 for(int32_t k=0; k<2; k++)
3649 {
3650 if(LayerMaskInt[k+1]!=0)
3651 {
3652 layermap=layer->layermap[k]-1;
3653
3654 if(layermap>-1 && layermap<map_count)
3655 {
3656 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3657
3658 auto data = TheMaps[layerscreen].data[c];
3659 auto cs = TheMaps[layerscreen].cset[c];
3660 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3661 }
3662 }
3663 }
3664
3665 for(int32_t k=2; k<4; k++)
3666 {
3667 if(LayerMaskInt[k+1]!=0)
3668 {
3669 layermap=layer->layermap[k]-1;
3670
3671 if(layermap>-1 && layermap<map_count)
3672 {
3673 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3674 auto data = TheMaps[layerscreen].data[c];
3675 auto cs = TheMaps[layerscreen].cset[c];
3676 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3677 }
3678 }
3679 }
3680
3681 //Overhead L0
3682 if(LayerMaskInt[0]!=0)
3683 {
3684 auto data = TheMaps[layerscreen].data[c];
3685 if(combo_class_buf[combobuf[data].type].overhead)
3686 {
3687 auto cs = TheMaps[layerscreen].cset[c];
3688 drawcombo(dest,x,y,data,cs,0,0);
3689 }
3690 }
3691 //Overhead L1/2
3692 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3693 {
3694 for(int32_t k = 0; k < 2; ++k)
3695 {
3696 if(LayerMaskInt[k+1]!=0)
3697 {
3698 layermap=layer->layermap[k]-1;
3699
3700 if(layermap>-1 && layermap<map_count)
3701 {
3702 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3703 auto data = TheMaps[layerscreen].data[c];
3704 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3705 auto cs = TheMaps[layerscreen].cset[c];
3706 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3707 }
3708 }
3709 }
3710 }
3711
3712
3713 for(int32_t k=4; k<6; k++)
3714 {
3715 if(LayerMaskInt[k+1]!=0)
3716 {
3717 layermap=layer->layermap[k]-1;
3718
3719 if(layermap>-1 && layermap<map_count)
3720 {
3721 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3722 auto data = TheMaps[layerscreen].data[c];
3723 auto cs = TheMaps[layerscreen].cset[c];
3724 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3725 }
3726 }
3727 }
3728
3729 if(flags&cWALK)
3730 {
3731 if(LayerMaskInt[0]!=0)
3732 {
3733 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3734 }
3735
3736 for(int32_t k=0; k<2; k++)
3737 {
3738 if(LayerMaskInt[k+1]!=0)
3739 {
3740 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3741 }
3742 }
3743 }
3744
3745 if(flags&cFLAGS)
3746 {
3747 if(LayerMaskInt[CurrentLayer]!=0)
3748 {
3749 int32_t i = c;
3750 //for(int32_t i=c; i==c; i++)
3751 {
3752 if(CurrentLayer==0)
3753 {
3754 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3755 }
3756 else
3757 {
3758 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3759
3760 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3761 {
3762 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3763 TheMaps[_lscr].data[i],
3764 TheMaps[_lscr].cset[i], flags|dark,
3765 TheMaps[_lscr].sflag[i]);
3766 }
3767 }
3768 }
3769 }
3770 }
3771
3772 if(ShowMisalignments)
3773 {
3774 switch(c)
3775 {
3776 case 0:
3777 check_alignments(dest,x,y,scr);
3778 break;
3779
3780 case 15:
3781 check_alignments(dest,x-240,y,scr);
3782 break;
3783
3784 case 160:
3785 check_alignments(dest,x,y-160,scr);
3786 break;
3787
3788 case 175:
3789 check_alignments(dest,x-240,y-160,scr);
3790 break;
3791 }
3792 }
3793
3794 resize_mouse_pos=false;
3795
3796 }
3797
3798 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3799 {
3800 if (InvalidBG == 2)
3801 {
3802 draw_checkerboard(dest, x, y, 16);
3803 }
3804 else if(InvalidBG == 1)
3805 {
3806 for(int32_t dy=0; dy<16; dy++)
3807 {
3808 for(int32_t dx=0; dx<16; dx++)
3809 {
3810 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3811 }
3812 }
3813 }
3814 else
3815 {
3816 rectfill(dest, x, y, x+15, y+15, vc(0));
3817 rect(dest, x, y, x+15, y+15, vc(15));
3818 line(dest, x, y, x+15, y+15, vc(15));
3819 line(dest, x, y+15, x+15, y, vc(15));
3820 }
3821 }
3822
3823 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3824 {
3825 if (InvalidBG == 2)
3826 {
3827 for(int32_t q = 0; q < 11; ++q)
3828 draw_checkerboard(dest, x, y + q * 16, 16);
3829 }
3830 else if(InvalidBG == 1)
3831 {
3832 for(int32_t dy=0; dy<176; dy++)
3833 {
3834 for(int32_t dx=0; dx<16; dx++)
3835 {
3836 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3837 }
3838 }
3839 }
3840 else
3841 {
3842 rectfill(dest, x, y, x+15, y+175, vc(0));
3843 rect(dest, x, y, x+15, y+175, vc(15));
3844 line(dest, x, y, x+15, y+175, vc(15));
3845 line(dest, x, y+175, x+15, y, vc(15));
3846 }
3847 }
3848
3849 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3850 {
3851 if (InvalidBG == 2)
3852 {
3853 for (int32_t q = 0; q < 16; ++q)
3854 draw_checkerboard(dest, x + q * 16, y, 16);
3855 }
3856 else if(InvalidBG == 1)
3857 {
3858 for(int32_t dy=0; dy<16; dy++)
3859 {
3860 for(int32_t dx=0; dx<256; dx++)
3861 {
3862 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3863 }
3864 }
3865 }
3866 else
3867 {
3868 rectfill(dest, x, y, x+255, y+15, vc(0));
3869 rect(dest, x, y, x+255, y+15, vc(15));
3870 line(dest, x, y, x+255, y+15, vc(15));
3871 line(dest, x, y+15, x+255, y, vc(15));
3872 }
3873 }
3874
3875 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3876 {
3877 for(int32_t i=0; i<176; i++)
3878 {
3879 word cmbdat = screens[TEMPLATE].data[i];
3880 byte cmbcset = screens[TEMPLATE].cset[i];
3881 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3882 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3883 }
3884 }
3885
3886 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3887 {
3888 for(int32_t i=0; i<176; i++)
3889 {
3890 word cmbdat = screens[TEMPLATE2].data[i];
3891 byte cmbcset = screens[TEMPLATE2].cset[i];
3892 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3893 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3894 }
3895 }
3896
3897 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3898 {
3899 word cmbdat = screens[TEMPLATE].data[pos];
3900 byte cmbcset = screens[TEMPLATE].cset[pos];
3901 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3902 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3903 }
3904
3905 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3906 {
3907 word cmbdat = screens[currscr].secretcombo[scombo];
3908 byte cmbcset = screens[currscr].secretcset[scombo];
3909 byte cmbflag = screens[currscr].secretflag[scombo];
3910 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3911 }
3912
3913 void zmap::scroll(int32_t dir, bool warp)
3914 {
3915 if(currmap<map_count)
3916 {
3917 switch(dir)
3918 {
3919 case up:
3920 if(warp && Map.CurrScr()->flags2&wfUP)
3921 {
3922 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3923 }
3924 else if(currscr>15)
3925 {
3926 setCurrScr(currscr-16);
3927 }
3928
3929 break;
3930
3931 case down:
3932 if(warp && Map.CurrScr()->flags2&wfDOWN)
3933 {
3934 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3935 }
3936 else if(currscr<MAPSCRS-16)
3937 {
3938 setCurrScr(currscr+16);
3939 }
3940
3941 break;
3942
3943 case left:
3944 if(warp && Map.CurrScr()->flags2&wfLEFT)
3945 {
3946 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3947 }
3948 else if(currscr&15)
3949 {
3950 setCurrScr(currscr-1);
3951 }
3952
3953 break;
3954
3955 case right:
3956 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3957 {
3958 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3959 }
3960 else if((currscr&15)<15 && currscr<MAPSCRS-1)
3961 {
3962 setCurrScr(currscr+1);
3963 }
3964
3965 break;
3966 }
3967 }
3968 }
3969
3970 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3971 {
3972 switch(side)
3973 {
3974 case up:
3975 switch(door)
3976 {
3977 case dWALL:
3978 case dBOMB:
3979 case dWALK:
3980 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3981 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3982 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3983 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3984 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3985 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3986 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3987 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3988 break;
3989
3990 default:
3991 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3992 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3993 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3994 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3995 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3996 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3997 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3998 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3999 break;
4000 }
4001
4002 break;
4003
4004 case down:
4005 switch(door)
4006 {
4007 case dWALL:
4008 case dBOMB:
4009 case dWALK:
4010 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4011 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4012 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4013 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4014 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4015 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4016 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4017 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4018 break;
4019
4020 default:
4021 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4022 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4023 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4024 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4025 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4026 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4027 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4028 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4029 break;
4030 }
4031
4032 break;
4033
4034 case left:
4035 switch(door)
4036 {
4037 case dWALL:
4038 case dBOMB:
4039 case dWALK:
4040 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4041 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4042 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4043 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4044 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4045 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4046 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4047 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4048 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4049 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4050 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4051 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4052 break;
4053
4054 default:
4055 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4056 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4057 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4058 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4059 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4060 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4061 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4062 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4063 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4064 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4065 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4066 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4067 break;
4068 }
4069
4070 break;
4071
4072 case right:
4073 switch(door)
4074 {
4075 case dWALL:
4076 case dBOMB:
4077 case dWALK:
4078 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4079 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4080 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4081 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4082 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4083 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4084 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4085 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4086 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4087 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4088 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4089 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4090 break;
4091
4092 default:
4093 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4094 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4095 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4096 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4097 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4098 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4099 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4100 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4101 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4102 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4103 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4104 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4105 break;
4106 }
4107
4108 break;
4109 }
4110 }
4111 void zmap::DoPutDoorCommand(int side, int door, bool force)
4112 {
4113 if(!force && screens[currscr].door[side] == door)
4114 return;
4115 bool already_list = InListCommand();
4116 if(!already_list)
4117 StartListCommand();
4118 DoSetDoorCommand(currscr,side,door);
4119 if(door != dNONE)
4120 {
4121 word data[176] = {0};
4122 byte cset[176] = {0};
4123 fetch_door(side, door, screens[currscr].door_combo_set, data, cset);
4124 for(int q = 0; q < 176; ++q)
4125 if(data[q])
4126 DoSetComboCommand(currmap,currscr,q,data[q],cset[q]);
4127 }
4128 if(!already_list)
4129 FinishListCommand();
4130 }
4131 void zmap::putdoor(int32_t scr,int32_t side,int32_t door)
4132 {
4133 if(screens[scr].door[side] == door)
4134 return;
4135 screens[scr].door[side] = door;
4136 if(door != dNONE)
4137 {
4138 word data[176] = {0};
4139 byte cset[176] = {0};
4140 fetch_door(side, door, screens[scr].door_combo_set, data, cset);
4141 for(int q = 0; q < 176; ++q)
4142 if(data[q])
4143 {
4144 screens[scr].data[q] = data[q];
4145 screens[scr].cset[q] = cset[q];
4146 }
4147 }
4148 }
4149
4150 void list_command::execute()
4151 {
4152 for (auto command : commands)
4153 {
4154 command->execute();
4155 }
4156 }
4157
4158 void list_command::undo()
4159 {
4160 for (int i = commands.size() - 1; i >= 0; i--)
4161 {
4162 commands[i]->undo();
4163 }
4164 }
4165
4166 int list_command::size()
4167 {
4168 int s = 0;
4169 for (auto command : commands)
4170 {
4171 s += command->size();
4172 }
4173 return s;
4174 }
4175
4176 void set_combo_command::execute()
4177 {
4178 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4179 if(!mapscr_ptr) return;
4180
4181 mapscr_ptr->valid |= mVALID;
4182 if (combo != -1) mapscr_ptr->data[pos] = combo;
4183 mapscr_ptr->cset[pos] = cset;
4184 }
4185
4186 void set_combo_command::undo()
4187 {
4188 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4189 if(!mapscr_ptr) return;
4190 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4191 mapscr_ptr->cset[pos] = prev_cset;
4192 }
4193
4194 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4195 {
4196 std::array<int, 2> inita_arr;
4197 std::copy(std::begin(ffc.inita), std::end(ffc.inita), inita_arr.begin());
4198 std::array<int, 8> initd_arr;
4199 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4200
4201 return {
4202 .x = ffc.x,
4203 .y = ffc.y,
4204 .vx = ffc.vx,
4205 .vy = ffc.vy,
4206 .ax = ffc.ax,
4207 .ay = ffc.ay,
4208 .data = ffc.data,
4209 .cset = ffc.cset,
4210 .delay = ffc.delay,
4211 .link = ffc.link,
4212 .script = ffc.script,
4213 .tw = ffc.txsz,
4214 .th = ffc.tysz,
4215 .ew = ffc.hit_width,
4216 .eh = ffc.hit_height,
4217 .flags = ffc.flags,
4218 .inita = inita_arr,
4219 .initd = initd_arr,
4220 };
4221 }
4222
4223 void set_ffc_command::execute()
4224 {
4225 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4226 if(!mapscr_ptr) return;
4227
4228 mapscr_ptr->valid |= mVALID;
4229 mapscr_ptr->ffcs[i].x = data.x;
4230 mapscr_ptr->ffcs[i].y = data.y;
4231 mapscr_ptr->ffcs[i].vx = data.vx;
4232 mapscr_ptr->ffcs[i].vy = data.vy;
4233 mapscr_ptr->ffcs[i].ax = data.ax;
4234 mapscr_ptr->ffcs[i].ay = data.ay;
4235 mapscr_ptr->ffcs[i].data = data.data;
4236 mapscr_ptr->ffcs[i].cset = data.cset;
4237 mapscr_ptr->ffcs[i].delay = data.delay;
4238 mapscr_ptr->ffcs[i].link = data.link;
4239 mapscr_ptr->ffcs[i].script = data.script;
4240 mapscr_ptr->ffcs[i].flags = data.flags;
4241 mapscr_ptr->ffEffectWidth(i, data.ew);
4242 mapscr_ptr->ffEffectHeight(i, data.eh);
4243 mapscr_ptr->ffTileWidth(i, data.tw);
4244 mapscr_ptr->ffTileHeight(i, data.th);
4245 std::copy(std::begin(data.inita), std::end(data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4246 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4247 mapscr_ptr->ffcCountMarkDirty();
4248 mapscr_ptr->ffcs[i].updateSolid();
4249 }
4250
4251 void set_ffc_command::undo()
4252 {
4253 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4254 if(!mapscr_ptr) return;
4255
4256 mapscr_ptr->ffcs[i].x = prev_data.x;
4257 mapscr_ptr->ffcs[i].y = prev_data.y;
4258 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4259 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4260 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4261 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4262 mapscr_ptr->ffcs[i].data = prev_data.data;
4263 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4264 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4265 mapscr_ptr->ffcs[i].link = prev_data.link;
4266 mapscr_ptr->ffcs[i].script = prev_data.script;
4267 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4268 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4269 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4270 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4271 mapscr_ptr->ffTileHeight(i, prev_data.th);
4272 std::copy(std::begin(prev_data.inita), std::end(prev_data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4273 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4274 mapscr_ptr->ffcCountMarkDirty();
4275 mapscr_ptr->ffcs[i].updateSolid();
4276 }
4277
4278 void set_flag_command::execute()
4279 {
4280 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4281 if(!mapscr_ptr) return;
4282
4283 mapscr_ptr->valid |= mVALID;
4284 mapscr_ptr->sflag[pos] = flag;
4285 }
4286
4287 void set_flag_command::undo()
4288 {
4289 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4290 if(!mapscr_ptr) return;
4291 mapscr_ptr->sflag[pos] = prev_flag;
4292 }
4293
4294 void set_door_command::execute()
4295 {
4296 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4297 if(!mapscr_ptr) return;
4298
4299 mapscr_ptr->valid |= mVALID;
4300 mapscr_ptr->door[side] = door;
4301 }
4302
4303 void set_door_command::undo()
4304 {
4305 Map.AbsoluteScr(view_map, view_scr)->door[side] = prev_door;
4306 }
4307
4308 void set_dcs_command::execute()
4309 {
4310 auto* mapscr_ptr = Map.AbsoluteScr(view_map, view_scr);
4311 if(!mapscr_ptr) return;
4312
4313 mapscr_ptr->valid |= mVALID;
4314 mapscr_ptr->door_combo_set = dcs;
4315 }
4316
4317 void set_dcs_command::undo()
4318 {
4319 Map.AbsoluteScr(view_map, view_scr)->door_combo_set = prev_dcs;
4320 }
4321
4322 void paste_screen_command::execute()
4323 {
4324 perform(screen.get());
4325 }
4326
4327 void paste_screen_command::undo()
4328 {
4329 if (prev_screens.size() > 1)
4330 {
4331 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4332 ASSERT(prev_screens.size() == 128);
4333 for (int i = 0; i < 128; i++)
4334 {
4335 copy_mapscr(Map.AbsoluteScr(view_map, i), prev_screens[i].get());
4336 // TODO: why not just this?
4337 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4338 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4339 }
4340 return;
4341 }
4342
4343 perform(prev_screens[0].get());
4344 }
4345
4346 int paste_screen_command::size()
4347 {
4348 return prev_screens.size() + 1;
4349 }
4350
4351 void paste_screen_command::perform(mapscr* to)
4352 {
4353 if (to)
4354 {
4355 switch (type) {
4356 case ScreenAll: Map.PasteAll(*to); break;
4357 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4358 case ScreenData: Map.PasteScreenData(*to); break;
4359 case ScreenDoors: Map.PasteDoors(*to); break;
4360 case ScreenEnemies: Map.PasteEnemies(*to); break;
4361 case ScreenFFCombos: Map.PasteFFCombos(*to); break;
4362 case ScreenGuy: Map.PasteGuy(*to); break;
4363 case ScreenLayers: Map.PasteLayers(*to); break;
4364 case ScreenPalette: Map.PastePalette(*to); break;
4365 case ScreenPartial: Map.Paste(*to); break;
4366 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4367 case ScreenRoom: Map.PasteRoom(*to); break;
4368 case ScreenSecretCombos: Map.PasteSecretCombos(*to); break;
4369 case ScreenUnderCombo: Map.PasteUnderCombo(*to); break;
4370 case ScreenWarpLocations: Map.PasteWarpLocations(*to); break;
4371 case ScreenWarps: Map.PasteWarps(*to); break;
4372 }
4373 }
4374 else
4375 {
4376 Map.clearscr(view_scr);
4377 }
4378 refresh(rALL);
4379 }
4380
4381 void set_screen_command::execute()
4382 {
4383 if (screen)
4384 {
4385 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), screen.get());
4386 }
4387 else
4388 {
4389 Map.clearscr(view_scr);
4390 }
4391 refresh(rALL);
4392 }
4393
4394 void set_screen_command::undo()
4395 {
4396 if (prev_screen)
4397 {
4398 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), prev_screen.get());
4399 }
4400 else
4401 {
4402 Map.clearscr(view_scr);
4403 }
4404 refresh(rALL);
4405 }
4406
4407 int set_screen_command::size()
4408 {
4409 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4410 }
4411
4412 extern byte relational_tile_grid[11+(rtgyo*2)][16+(rtgxo*2)];
4413
4414 void tile_grid_draw_command::execute()
4415 {
4416 util::copy_2d_array<byte, 15, 20>(tile_grid, relational_tile_grid);
4417 }
4418
4419 void tile_grid_draw_command::undo()
4420 {
4421 util::copy_2d_array<byte, 15, 20>(prev_tile_grid, relational_tile_grid);
4422 }
4423
4424 static std::shared_ptr<list_command> current_list_command;
4425 void zmap::StartListCommand()
4426 {
4427 ASSERT(!current_list_command);
4428 current_list_command.reset(new list_command);
4429 }
4430
4431 void zmap::FinishListCommand()
4432 {
4433 if (current_list_command->commands.size() == 1)
4434 {
4435 undo_stack.push_back(current_list_command->commands[0]);
4436 }
4437 else if (current_list_command->commands.size() > 1)
4438 {
4439 undo_stack.push_back(current_list_command);
4440 }
4441 CapCommandHistory();
4442 current_list_command = nullptr;
4443 }
4444
4445 void zmap::RevokeListCommand()
4446 {
4447 current_list_command->undo();
4448 current_list_command = nullptr;
4449 }
4450
4451 bool zmap::InListCommand() const
4452 {
4453 return current_list_command ? true : false;
4454 }
4455
4456 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4457 {
4458 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4459 if (!skip_execute) command->execute();
4460 if (current_list_command)
4461 {
4462 current_list_command->commands.push_back(command);
4463 if (current_list_command->commands.size() == 1)
4464 {
4465 current_list_command->view_map = command->view_map;
4466 current_list_command->view_scr = command->view_scr;
4467 }
4468 }
4469 else
4470 {
4471 undo_stack.push_back(command);
4472 CapCommandHistory();
4473 }
4474 saved = false;
4475 }
4476
4477 void zmap::UndoCommand()
4478 {
4479 if (undo_stack.size() <= 0) return;
4480
4481 // If not currently looking at the associated screen, first change the view
4482 // and wait for the next call to actually undo this command.
4483 auto command = undo_stack.back();
4484 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4485 {
4486 setCurrentView(command->view_map, command->view_scr);
4487 return;
4488 }
4489
4490 command->undo();
4491 redo_stack.push(command);
4492 undo_stack.pop_back();
4493 saved = false;
4494 }
4495
4496 void zmap::RedoCommand()
4497 {
4498 if (redo_stack.size() <= 0) return;
4499
4500 // If not currently looking at the associated screen, first change the view
4501 // and wait for the next call to actually execute this command.
4502 auto command = redo_stack.top();
4503 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4504 {
4505 setCurrentView(command->view_map, command->view_scr);
4506 return;
4507 }
4508
4509 command->execute();
4510 undo_stack.push_back(command);
4511 redo_stack.pop();
4512 saved = false;
4513 }
4514
4515 9 void zmap::ClearCommandHistory()
4516 {
4517 9 current_list_command = nullptr;
4518 9 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4519 9 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4520 9 }
4521
4522 // Extra amount is from mapscr's vectors.
4523 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4524 // Allow the undo system to use roughly 100 MB of memory.
4525 // This doesn't count the memory used by commands that don't store a mapscr,
4526 // but that should be negligible.
4527 9 static int max_command_size = 100e6 / size_of_mapscr;
4528 void zmap::CapCommandHistory()
4529 {
4530 int size;
4531 do
4532 {
4533 size = 0;
4534 for (auto command : undo_stack)
4535 {
4536 size += command->size();
4537 }
4538 if (size > max_command_size) undo_stack.pop_front();
4539 } while (size > max_command_size);
4540 }
4541
4542 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4543 {
4544 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4545 if(!mapscr_ptr) return;
4546 std::shared_ptr<set_combo_command> command(new set_combo_command);
4547 command->view_map = currmap;
4548 command->view_scr = currscr;
4549 command->map = map;
4550 command->scr = scr;
4551 command->pos = pos;
4552 command->combo = combo;
4553 command->cset = cset;
4554 command->prev_combo = mapscr_ptr->data[pos];
4555 command->prev_cset = mapscr_ptr->cset[pos];
4556 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4557 {
4558 // nothing to do...
4559 return;
4560 }
4561
4562 ExecuteCommand(command);
4563 }
4564
4565 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4566 {
4567 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4568 if(!mapscr_ptr) return;
4569
4570 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4571
4572 std::array<int, 2> inita_arr;
4573 std::copy(std::begin(mapscr_ptr->ffcs[i].inita), std::end(mapscr_ptr->ffcs[i].inita), inita_arr.begin());
4574 std::array<int, 8> initd_arr;
4575 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4576
4577 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4578
4579 command->view_map = currmap;
4580 command->view_scr = currscr;
4581 command->map = map;
4582 command->scr = scr;
4583 command->i = i;
4584 command->data = data;
4585 command->prev_data = prev_data;
4586 if (data == prev_data)
4587 {
4588 // nothing to do...
4589 return;
4590 }
4591
4592 ExecuteCommand(command);
4593 }
4594
4595 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4596 {
4597 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4598 if(!mapscr_ptr) return;
4599 std::shared_ptr<set_flag_command> command(new set_flag_command);
4600 command->view_map = currmap;
4601 command->view_scr = currscr;
4602 command->map = map;
4603 command->scr = scr;
4604 command->pos = pos;
4605 command->flag = flag;
4606 command->prev_flag = mapscr_ptr->sflag[pos];
4607 if (command->flag == command->prev_flag)
4608 {
4609 // nothing to do...
4610 return;
4611 }
4612
4613 ExecuteCommand(command);
4614 }
4615
4616 void zmap::DoSetDoorCommand(int scr, int side, int door)
4617 {
4618 if(screens[scr].door[side] == door)
4619 return;
4620 std::shared_ptr<set_door_command> command(new set_door_command);
4621 command->view_map = currmap;
4622 command->view_scr = scr;
4623 command->side = side;
4624 command->door = door;
4625 command->prev_door = screens[scr].door[side];
4626
4627 ExecuteCommand(command);
4628 }
4629 void zmap::DoSetDCSCommand(int dcs)
4630 {
4631 if(screens[currscr].door_combo_set == dcs)
4632 return;
4633 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4634 command->view_map = currmap;
4635 command->view_scr = currscr;
4636 command->dcs = dcs;
4637 command->prev_dcs = screens[currscr].door_combo_set;
4638
4639 ExecuteCommand(command);
4640 }
4641
4642 void zmap::DoPasteScreenCommand(PasteCommandType type, int data)
4643 {
4644 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4645 command->view_map = currmap;
4646 command->view_scr = currscr;
4647 command->type = type;
4648 command->data = data;
4649 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4650
4651 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4652 {
4653 for (int i=0; i < 128; i++)
4654 {
4655 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4656 }
4657 }
4658 else
4659 {
4660 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[currscr])));
4661 }
4662
4663 ExecuteCommand(command);
4664 }
4665
4666 void zmap::DoClearScreenCommand()
4667 {
4668 std::shared_ptr<set_screen_command> command(new set_screen_command);
4669 command->view_map = currmap;
4670 command->view_scr = currscr;
4671 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[currscr]));
4672 command->screen = std::shared_ptr<mapscr>(nullptr);
4673
4674 ExecuteCommand(command);
4675 }
4676
4677 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int scr)
4678 {
4679 std::shared_ptr<set_screen_command> command(new set_screen_command);
4680 command->view_map = currmap;
4681 command->view_scr = currscr;
4682 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4683 Template(floorcombo, floorcset, scr);
4684 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4685
4686 ExecuteCommand(command, true);
4687 }
4688
4689 void zmap::Copy()
4690 {
4691 if(screens[currscr].valid&mVALID)
4692 {
4693 copy_mapscr(&copymapscr, &screens[currscr]);
4694 //copymapscr=screens[currscr];
4695 can_paste=true;
4696 copymap=currmap;
4697 copyscr=currscr;
4698 copyscrdata = zinit.screen_data[currmap*MAPSCRS+currscr];
4699 copyffc = -1;
4700 }
4701 }
4702
4703 void zmap::CopyFFC(int32_t n)
4704 {
4705 if(screens[currscr].valid&mVALID)
4706 {
4707 copy_mapscr(&copymapscr, &screens[currscr]);
4708 // Can't paste the screen itself
4709 can_paste = false;
4710 copymap=currmap;
4711 copyscr=currscr;
4712 copyffc = n;
4713 }
4714 }
4715
4716 void zmap::Paste(const mapscr& copymapscr)
4717 {
4718 if(can_paste)
4719 {
4720 int32_t oldcolor=getcolor();
4721
4722 if(!(screens[currscr].valid&mVALID))
4723 {
4724 screens[currscr].valid |= mVALID;
4725 screens[currscr].color = copymapscr.color;
4726 }
4727
4728 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4729
4730 for(int32_t i=0; i<4; i++)
4731 {
4732 screens[currscr].door[i]=copymapscr.door[i];
4733 }
4734
4735 for(int32_t i=0; i<176; i++)
4736 {
4737 screens[currscr].data[i] = copymapscr.data[i];
4738 screens[currscr].cset[i] = copymapscr.cset[i];
4739 screens[currscr].sflag[i] = copymapscr.sflag[i];
4740 }
4741
4742 int32_t newcolor=getcolor();
4743 loadlvlpal(newcolor);
4744
4745 if(newcolor!=oldcolor)
4746 {
4747 rebuild_trans_table();
4748 }
4749
4750 saved=false;
4751 }
4752 }
4753
4754 void zmap::PasteUnderCombo(const mapscr& copymapscr)
4755 {
4756 if(can_paste)
4757 {
4758 screens[currscr].undercombo = copymapscr.undercombo;
4759 screens[currscr].undercset = copymapscr.undercset;
4760 saved=false;
4761 }
4762 }
4763
4764 void zmap::PasteSecretCombos(const mapscr& copymapscr)
4765 {
4766 if(can_paste)
4767 {
4768 for(int32_t i=0; i<128; i++)
4769 {
4770 screens[currscr].secretcombo[i] = copymapscr.secretcombo[i];
4771 screens[currscr].secretcset[i] = copymapscr.secretcset[i];
4772 screens[currscr].secretflag[i] = copymapscr.secretflag[i];
4773 }
4774
4775 saved=false;
4776 }
4777 }
4778
4779 // TODO const mapscr& copymapscr
4780 void zmap::PasteFFCombos(mapscr& copymapscr)
4781 {
4782 if(can_paste)
4783 {
4784 word c = copymapscr.numFFC();
4785 for(word i=0; i<c; i++)
4786 screens[currscr].ffcs[i] = copymapscr.ffcs[i];
4787 for(word i = c; i < MAXFFCS; ++i)
4788 screens[currscr].ffcs[i].clear();
4789
4790 saved=false;
4791 }
4792 }
4793
4794 void zmap::PasteWarps(const mapscr& copymapscr)
4795 {
4796 if(can_paste)
4797 {
4798 screens[currscr].sidewarpindex = copymapscr.sidewarpindex;
4799
4800 for(int32_t i=0; i<4; i++)
4801 {
4802 screens[currscr].tilewarptype[i] = copymapscr.tilewarptype[i];
4803 screens[currscr].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4804 screens[currscr].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4805 screens[currscr].sidewarptype[i] = copymapscr.sidewarptype[i];
4806 screens[currscr].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4807 screens[currscr].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4808 screens[currscr].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4809 screens[currscr].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4810 screens[currscr].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4811 screens[currscr].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4812 }
4813
4814 saved=false;
4815 }
4816 }
4817
4818 void zmap::PasteScreenData(const mapscr& copymapscr)
4819 {
4820 if(can_paste)
4821 {
4822 screens[currscr].csensitive = copymapscr.csensitive;
4823 screens[currscr].oceansfx = copymapscr.oceansfx;
4824 screens[currscr].bosssfx = copymapscr.bosssfx;
4825 screens[currscr].secretsfx = copymapscr.secretsfx;
4826 screens[currscr].holdupsfx = copymapscr.holdupsfx;
4827 screens[currscr].flags = copymapscr.flags;
4828 screens[currscr].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4829 screens[currscr].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4830 screens[currscr].flags3 = copymapscr.flags3;
4831 screens[currscr].flags4 = copymapscr.flags4;
4832 screens[currscr].flags5 = copymapscr.flags5;
4833 screens[currscr].flags6 = copymapscr.flags6;
4834 screens[currscr].flags7 = copymapscr.flags7;
4835 screens[currscr].flags8 = copymapscr.flags8;
4836 screens[currscr].flags9 = copymapscr.flags9;
4837 screens[currscr].flags10 = copymapscr.flags10;
4838 screens[currscr].item = copymapscr.item;
4839 screens[currscr].hasitem = copymapscr.hasitem;
4840 screens[currscr].itemx = copymapscr.itemx;
4841 screens[currscr].itemy = copymapscr.itemy;
4842 screens[currscr].nextmap = copymapscr.nextmap;
4843 screens[currscr].nextscr = copymapscr.nextscr;
4844 screens[currscr].nocarry = copymapscr.nocarry;
4845 screens[currscr].noreset = copymapscr.noreset;
4846 screens[currscr].path[0] = copymapscr.path[0];
4847 screens[currscr].path[1] = copymapscr.path[1];
4848 screens[currscr].path[2] = copymapscr.path[2];
4849 screens[currscr].path[3] = copymapscr.path[3];
4850 screens[currscr].pattern = copymapscr.pattern;
4851 screens[currscr].exitdir = copymapscr.exitdir;
4852 screens[currscr].enemyflags = copymapscr.enemyflags;
4853 screens[currscr].screen_midi = copymapscr.screen_midi;
4854 screens[currscr].stairx = copymapscr.stairx;
4855 screens[currscr].stairy = copymapscr.stairy;
4856 screens[currscr].timedwarptics = copymapscr.timedwarptics;
4857 saved=false;
4858 }
4859 }
4860
4861 void zmap::PasteWarpLocations(const mapscr& copymapscr)
4862 {
4863 if(can_paste)
4864 {
4865 screens[currscr].warpreturnc = copymapscr.warpreturnc;
4866 screens[currscr].warparrivalx = copymapscr.warparrivalx;
4867 screens[currscr].warparrivaly = copymapscr.warparrivaly;
4868
4869 for(int32_t i=0; i<4; i++)
4870 {
4871 screens[currscr].warpreturnx[i] = copymapscr.warpreturnx[i];
4872 screens[currscr].warpreturny[i] = copymapscr.warpreturny[i];
4873 }
4874
4875 saved=false;
4876 }
4877 }
4878
4879 void zmap::PasteDoors(const mapscr& copymapscr)
4880 {
4881 if(can_paste)
4882 {
4883 for(int32_t i=0; i<4; i++)
4884 screens[currscr].door[i] = copymapscr.door[i];
4885
4886 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4887 saved=false;
4888 }
4889 }
4890
4891 void zmap::PasteLayers(const mapscr& copymapscr)
4892 {
4893 if(can_paste)
4894 {
4895 for(int32_t i=0; i<6; i++)
4896 {
4897 screens[currscr].layermap[i] = copymapscr.layermap[i];
4898 screens[currscr].layerscreen[i] = copymapscr.layerscreen[i];
4899 screens[currscr].layeropacity[i] = copymapscr.layeropacity[i];
4900 }
4901
4902 saved=false;
4903 }
4904 }
4905
4906 void zmap::PasteRoom(const mapscr& copymapscr)
4907 {
4908 if(can_paste)
4909 {
4910 screens[currscr].room = copymapscr.room;
4911 screens[currscr].catchall = copymapscr.catchall;
4912 saved=false;
4913 }
4914 }
4915
4916 void zmap::PasteGuy(const mapscr& copymapscr)
4917 {
4918 if(can_paste)
4919 {
4920 screens[currscr].guy = copymapscr.guy;
4921 screens[currscr].guytile = copymapscr.guytile;
4922 screens[currscr].guycs = copymapscr.guycs;
4923 SETFLAG(screens[currscr].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4924 SETFLAG(screens[currscr].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4925 screens[currscr].str = copymapscr.str;
4926 saved=false;
4927 }
4928 }
4929
4930 void zmap::PastePalette(const mapscr& copymapscr)
4931 {
4932 if(can_paste)
4933 {
4934 int32_t oldcolor=getcolor();
4935 screens[currscr].color = copymapscr.color;
4936 int32_t newcolor=getcolor();
4937 loadlvlpal(newcolor);
4938
4939 screens[currscr].valid|=mVALID;
4940
4941 if(newcolor!=oldcolor)
4942 {
4943 rebuild_trans_table();
4944 }
4945
4946 saved=false;
4947 }
4948 }
4949
4950 void zmap::PasteAll(const mapscr& copymapscr)
4951 {
4952 if(can_paste)
4953 {
4954 int32_t oldcolor=getcolor();
4955 copy_mapscr(&screens[currscr], &copymapscr);
4956 zinit.screen_data[currmap*MAPSCRS+currscr] = copyscrdata;
4957 //screens[currscr]=copymapscr;
4958 int32_t newcolor=getcolor();
4959 loadlvlpal(newcolor);
4960
4961 screens[currscr].valid|=mVALID;
4962
4963 if(newcolor!=oldcolor)
4964 {
4965 rebuild_trans_table();
4966 }
4967
4968 saved=false;
4969 }
4970 }
4971
4972
4973 void zmap::PasteToAll(const mapscr& copymapscr)
4974 {
4975 if(can_paste)
4976 {
4977 int32_t oldcolor=getcolor();
4978
4979 for(int32_t x=0; x<128; x++)
4980 {
4981 if(!(screens[x].valid&mVALID))
4982 {
4983 screens[x].valid |= mVALID;
4984 screens[x].color = copymapscr.color;
4985 }
4986
4987 for(int32_t i=0; i<176; i++)
4988 {
4989 screens[x].data[i] = copymapscr.data[i];
4990 screens[x].cset[i] = copymapscr.cset[i];
4991 screens[x].sflag[i] = copymapscr.sflag[i];
4992 }
4993 }
4994
4995 int32_t newcolor=getcolor();
4996 loadlvlpal(newcolor);
4997
4998 if(!(screens[currscr].valid&mVALID))
4999 {
5000 newcolor=-1;
5001 }
5002
5003 if(newcolor!=oldcolor)
5004 {
5005 rebuild_trans_table();
5006 }
5007
5008 saved=false;
5009 }
5010 }
5011
5012 void zmap::PasteAllToAll(const mapscr& copymapscr)
5013 {
5014 if(can_paste)
5015 {
5016 int32_t oldcolor=getcolor();
5017
5018 for(int32_t x=0; x<128; x++)
5019 {
5020 copy_mapscr(&screens[x], &copymapscr);
5021 zinit.screen_data[currmap*MAPSCRS+x] = copyscrdata;
5022 //screens[x]=copymapscr;
5023 }
5024
5025 int32_t newcolor=getcolor();
5026 loadlvlpal(newcolor);
5027
5028 if(!(screens[currscr].valid&mVALID))
5029 {
5030 newcolor=-1;
5031 }
5032
5033 if(newcolor!=oldcolor)
5034 {
5035 rebuild_trans_table();
5036 }
5037
5038 saved=false;
5039 }
5040 }
5041
5042 void zmap::PasteEnemies(const mapscr& copymapscr)
5043 {
5044 if(can_paste)
5045 {
5046 for(int32_t i=0; i<10; i++)
5047 screens[currscr].enemy[i]=copymapscr.enemy[i];
5048 }
5049 }
5050
5051 void zmap::setCopyFFC(int32_t n)
5052 {
5053 copyffc = n;
5054 }
5055
5056 void zmap::update_combo_cycling()
5057 {
5058 if(!prv_mode||!prv_cmbcycle)
5059 {
5060 return;
5061 }
5062
5063 int32_t x;
5064 int32_t newdata[176];
5065 int32_t newcset[176];
5066 bool restartanim[MAXCOMBOS] = {0};
5067
5068 for(int32_t i=0; i<176; i++)
5069 {
5070 newdata[i]=-1;
5071 newcset[i]=-1;
5072
5073 x=prvscr.data[i];
5074
5075 //time to restart
5076 if((combobuf[x].aclk>=combobuf[x].speed) &&
5077 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5078 (combobuf[x].nextcombo!=0))
5079 {
5080 newdata[i]=combobuf[x].nextcombo;
5081 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5082 newcset[i]=combobuf[x].nextcset;
5083 int32_t c = newdata[i];
5084
5085 if(combobuf[c].animflags & AF_CYCLE)
5086 {
5087 restartanim[c]=true;
5088 }
5089 }
5090 }
5091
5092 for(int32_t i=0; i<176; i++)
5093 {
5094 x=prvscr.data[i];
5095
5096 //time to restart
5097 if((combobuf[x].aclk>=combobuf[x].speed) &&
5098 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5099 (combobuf[x].nextcombo!=0))
5100 {
5101 newdata[i]=combobuf[x].nextcombo;
5102 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5103 newcset[i]=combobuf[x].nextcset;
5104 int32_t c = newdata[i];
5105
5106 if(combobuf[c].animflags & AF_CYCLE)
5107 {
5108 restartanim[c]=true;
5109 }
5110 }
5111 }
5112
5113 for(int32_t i=0; i<176; i++)
5114 {
5115 if(newdata[i]==-1)
5116 continue;
5117
5118 prvscr.data[i]=newdata[i];
5119 prvscr.cset[i]=newcset[i];
5120 }
5121
5122 word maxffc = prvscr.numFFC();
5123 for(word i=0; i<maxffc; i++)
5124 {
5125 ffcdata& ffc = prvscr.ffcs[i];
5126 newcombo const& cmb = combobuf[ffc.data];
5127
5128 //time to restart
5129 if((cmb.aclk>=cmb.speed) &&
5130 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5131 (cmb.nextcombo!=0))
5132 {
5133 ffc.data = cmb.nextcombo;
5134 if(!(cmb.animflags & AF_CYCLENOCSET))
5135 ffc.cset=cmb.nextcset;
5136
5137 if(combobuf[ffc.data].animflags & AF_CYCLE)
5138 {
5139 restartanim[ffc.data]=true;
5140 }
5141 prvscr.ffcs[i].data = ffc.data;
5142 prvscr.ffcs[i].cset=ffc.cset;
5143 }
5144 }
5145
5146
5147 if(get_qr(qr_CMBCYCLELAYERS))
5148 {
5149 for(int32_t j=0; j<6; j++)
5150 {
5151 if(!prvlayers[j].valid)
5152 continue;
5153
5154 for(int32_t i=0; i<176; i++)
5155 {
5156 newdata[i]=-1;
5157 newcset[i]=-1;
5158
5159 x=(prvlayers[j]).data[i];
5160
5161 //time to restart
5162 if((combobuf[x].aclk>=combobuf[x].speed) &&
5163 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5164 (combobuf[x].nextcombo!=0))
5165 {
5166 newdata[i]=combobuf[x].nextcombo;
5167 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5168 newcset[i]=combobuf[x].nextcset;
5169 int32_t c = newdata[i];
5170
5171 if(combobuf[c].animflags & AF_CYCLE)
5172 {
5173 restartanim[c]=true;
5174 }
5175 }
5176 }
5177
5178 for(int32_t i=0; i<176; i++)
5179 {
5180 x=(prvlayers[j]).data[i];
5181
5182 //time to restart
5183 if((combobuf[x].aclk>=combobuf[x].speed) &&
5184 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5185 (combobuf[x].nextcombo!=0))
5186 {
5187 newdata[i]=combobuf[x].nextcombo;
5188 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5189 newcset[i]=combobuf[x].nextcset;
5190 int32_t c = newdata[i];
5191
5192 if(combobuf[c].animflags & AF_CYCLE)
5193 {
5194 restartanim[c]=true;
5195 }
5196 }
5197 }
5198
5199 for(int32_t i=0; i<176; i++)
5200 {
5201 if(newdata[i]==-1)
5202 continue;
5203
5204 prvlayers[j].data[i]=newdata[i];
5205 prvlayers[j].cset[i]=newcset[i];
5206 }
5207 }
5208 }
5209
5210 for(int32_t i=0; i<MAXCOMBOS; i++)
5211 {
5212 if(restartanim[i])
5213 {
5214 combobuf[i].tile = combobuf[i].o_tile;
5215 combobuf[i].cur_frame=0;
5216 combobuf[i].aclk = 0;
5217 }
5218 }
5219 }
5220
5221 void zmap::update_freeform_combos()
5222 {
5223 if(!prv_mode||!prv_cmbcycle)
5224 {
5225 return;
5226 }
5227
5228 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5229 word maxffc = prvscr.numFFC();
5230 for(int32_t i=0; i<maxffc; i++)
5231 {
5232 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5233 {
5234 for(int32_t j=0; j<maxffc; j++)
5235 {
5236 if(i!=j)
5237 {
5238 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5239 {
5240 if((((prvscr.ffcs[j].x.getInt())!=ffposx[i])||((prvscr.ffcs[j].y.getInt())!=ffposy[i]))&&(prvscr.ffcs[i].link==0))
5241 {
5242 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),ffprvx[i],ffprvy[i],prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5243 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(ffprvx[i]>-10000000&&ffprvy[i]>-10000000))
5244 {
5245 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5246 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5247 if(prvscr.ffcs[j].flags&ffc_changethis)
5248 {
5249 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5250 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5251 }
5252
5253 if(prvscr.ffcs[j].flags&ffc_changenext)
5254 prvscr.ffcs[i].data += 1;
5255
5256 if(prvscr.ffcs[j].flags&ffc_changeprev)
5257 prvscr.ffcs[i].data -= 1;
5258
5259 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5260 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5261 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5262
5263 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5264 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5265 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5266 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5267
5268 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5269 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5270 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5271 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5272 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5273
5274 if(prvscr.ffcs[i].flags&ffc_carryover)
5275 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5276 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5277
5278 prvscr.ffcs[i].flags&=~ffc_changer;
5279 ffposx[i]=(prvscr.ffcs[j].x.getInt());
5280 ffposy[i]=(prvscr.ffcs[j].y.getInt());
5281
5282 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5283 {
5284 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5285 }
5286
5287 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5288 {
5289 int32_t k=0;
5290
5291 if(prvscr.ffcs[j].flags&ffc_swapnext)
5292 k=j<(MAXFFCS-1)?j+1:0;
5293
5294 if(prvscr.ffcs[j].flags&ffc_swapprev)
5295 k=j>0?j-1:(MAXFFCS-1);
5296
5297 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5298 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5299 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5300 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5301 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5302 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5303 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5304 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5305 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5306 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5307 }
5308 }
5309 }
5310 }
5311 }
5312 }
5313
5314 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5315 {
5316 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5317 {
5318 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5319 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5320 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5321 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5322 }
5323 else
5324 {
5325 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5326 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5327 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5328 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5329 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5330 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5331
5332 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5333 {
5334 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5335
5336 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5337
5338 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5339
5340 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5341 }
5342 }
5343 }
5344 else
5345 {
5346 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5347 prvscr.ffcs[i].delay--;
5348 }
5349
5350 if(prvscr.ffcs[i].x<-32)
5351 {
5352 if(prvscr.flags6&fWRAPAROUNDFF)
5353 {
5354 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5355 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5356 }
5357 else
5358 {
5359 prvscr.ffcs[i].data = 0;
5360 prvscr.ffcs[i].flags&=~ffc_carryover;
5361 }
5362 }
5363
5364 if(prvscr.ffcs[i].y<-32)
5365 {
5366 if(prvscr.flags6&fWRAPAROUNDFF)
5367 {
5368 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5369 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5370 }
5371 else
5372 {
5373 prvscr.ffcs[i].data = 0;
5374 prvscr.ffcs[i].flags&=~ffc_carryover;
5375 }
5376 }
5377
5378 if(prvscr.ffcs[i].x>=288)
5379 {
5380 if(prvscr.flags6&fWRAPAROUNDFF)
5381 {
5382 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5383 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5384 }
5385 else
5386 {
5387 prvscr.ffcs[i].data = 0;
5388 prvscr.ffcs[i].flags&=~ffc_carryover;
5389 }
5390 }
5391
5392 if(prvscr.ffcs[i].y>=208)
5393 {
5394 if(prvscr.flags6&fWRAPAROUNDFF)
5395 {
5396 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5397 ffprvy[i] = prvscr.ffcs[i].x.getZLong();
5398 }
5399 else
5400 {
5401 prvscr.ffcs[i].data = 0;
5402 prvscr.ffcs[i].flags&=~ffc_carryover;
5403 }
5404 }
5405
5406 }
5407 }
5408 }
5409
5410 void zmap::goto_dmapscr(int dmap, int scr)
5411 {
5412 setCurrMap(DMaps[dmap].map);
5413 setCurrScr(scr+DMaps[dmap].xoff);
5414 }
5415 void zmap::goto_mapscr(int map, int scr)
5416 {
5417 setCurrMap(map);
5418 setCurrScr(scr);
5419 }
5420
5421 void zmap::dowarp(int32_t type, int32_t index)
5422 {
5423 set_warpback();
5424 if(type==0)
5425 {
5426
5427 int32_t dmap=screens[currscr].tilewarpdmap[index];
5428 int32_t scr=screens[currscr].tilewarpscr[index];
5429
5430 switch(screens[currscr].tilewarptype[index])
5431 {
5432 case wtCAVE:
5433 case wtNOWARP:
5434 break;
5435
5436 default:
5437 goto_dmapscr(dmap, scr);
5438 break;
5439 }
5440 }
5441 else if(type==1)
5442 {
5443 int32_t dmap=screens[currscr].sidewarpdmap[index];
5444 int32_t scr=screens[currscr].sidewarpscr[index];
5445
5446 switch(screens[currscr].sidewarptype[index])
5447 {
5448 case wtCAVE:
5449 case wtNOWARP:
5450 break;
5451
5452 default:
5453 goto_dmapscr(dmap, scr);
5454 break;
5455 }
5456 }
5457 }
5458
5459 extern int32_t prv_twon;
5460
5461 void zmap::prv_dowarp(int32_t type, int32_t index)
5462 {
5463 if(type==0)
5464 {
5465
5466 int32_t dmap=prvscr.tilewarpdmap[index];
5467 int32_t scr=prvscr.tilewarpscr[index];
5468
5469 switch(prvscr.tilewarptype[index])
5470 {
5471 case wtCAVE:
5472 case wtNOWARP:
5473 break;
5474
5475 default:
5476 //setCurrMap(DMaps[dmap].map);
5477 //setCurrScr(scr+DMaps[dmap].xoff);
5478 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5479 loadlvlpal(getcolor());
5480 rebuild_trans_table();
5481 //prv_cmbcycle=0;
5482 break;
5483 }
5484 }
5485 else if(type==1)
5486 {
5487 int32_t dmap=prvscr.sidewarpdmap[index];
5488 int32_t scr=prvscr.sidewarpscr[index];
5489
5490 switch(prvscr.sidewarptype[index])
5491 {
5492 case wtCAVE:
5493 case wtNOWARP:
5494 break;
5495
5496 default:
5497 //setCurrMap(DMaps[dmap].map);
5498 //setCurrScr(scr+DMaps[dmap].xoff);
5499 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5500 loadlvlpal(getcolor());
5501 rebuild_trans_table();
5502 //prv_cmbcycle=0;
5503 break;
5504 }
5505 }
5506
5507 if(prv_twon)
5508 {
5509 prv_time=get_prvscr()->timedwarptics;
5510 }
5511
5512 //also reset FFC information (so that changers will work correctly) -DD
5513 memset(ffposx,0xFF,sizeof(int16_t)*32);
5514 memset(ffposy,0xFF,sizeof(int16_t)*32);
5515 memset(ffprvx,0xFF,sizeof(float)*32);
5516 memset(ffprvy,0xFF,sizeof(float)*32);
5517 }
5518
5519 void zmap::dowarp2(int32_t ring,int32_t index)
5520 {
5521 set_warpback();
5522 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5523 }
5524
5525 void zmap::set_warpback()
5526 {
5527 warpbackmap = currmap;
5528 warpbackscreen = currscr;
5529 }
5530 bool zmap::has_warpback()
5531 {
5532 return warpbackmap && warpbackscreen
5533 && !(warpbackmap == currmap && warpbackscreen == currscr);
5534 }
5535 void zmap::warpback()
5536 {
5537 if(!has_warpback())
5538 return;
5539 int m = currmap, s = currscr;
5540 goto_mapscr(*warpbackmap, *warpbackscreen);
5541 warpbackmap = m;
5542 warpbackscreen = s;
5543 }
5544
5545 bool save_msgstrs(const char *path)
5546 {
5547 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5548
5549 if(!f)
5550 {
5551 return false;
5552 }
5553
5554 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5555 {
5556 pack_fclose(f);
5557 return true;
5558 }
5559
5560 pack_fclose(f);
5561 return false;
5562 }
5563
5564 1 bool save_strings_tsv(const char *path)
5565 {
5566 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5567
5568
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5569 {
5570 return false;
5571 }
5572
5573
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5574 {
5575 1 pack_fclose(f);
5576 1 return true;
5577 }
5578
5579 pack_fclose(f);
5580 return false;
5581 1 }
5582
5583 bool save_msgstrs_text(const char *path)
5584 {
5585 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5586
5587 if(!f)
5588 {
5589 return false;
5590 }
5591
5592 if(writestrings_text(f)==0)
5593 {
5594 pack_fclose(f);
5595 return true;
5596 }
5597
5598 pack_fclose(f);
5599 return false;
5600 }
5601
5602 bool load_msgstrs(const char *path, int32_t startstring)
5603 {
5604 //these are here to bypass compiler warnings about unused arguments
5605 startstring=startstring;
5606
5607 dword section_id;
5608 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5609
5610 if(!f)
5611 {
5612 return false;
5613 }
5614
5615 if(!p_mgetl(&section_id,f))
5616 {
5617 return false;
5618 }
5619
5620 if(section_id==ID_STRINGS)
5621 {
5622 if(readstrings(f, &header)==0)
5623 {
5624 pack_fclose(f);
5625 return true;
5626 }
5627 else
5628 {
5629 pack_fclose(f);
5630 return false;
5631 }
5632 }
5633
5634 pack_fclose(f);
5635 return false;
5636 }
5637
5638 bool load_strings_tsv(const char *path)
5639 {
5640 try
5641 {
5642 parse_strings_tsv(util::read_text_file(path));
5643 }
5644 catch (std::exception& ex)
5645 {
5646 InfoDialog("Import .tsv Error", ex.what()).show();
5647 return false;
5648 }
5649 return true;
5650 }
5651
5652 bool save_pals(const char *path)
5653 {
5654 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5655
5656 if(!f)
5657 {
5658 return false;
5659 }
5660
5661 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5662 {
5663 pack_fclose(f);
5664 return true;
5665 }
5666
5667 pack_fclose(f);
5668 return false;
5669 }
5670
5671 bool load_pals(const char *path, int32_t startcset)
5672 {
5673 dword section_id;
5674 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5675
5676 if(!f)
5677 {
5678 return false;
5679 }
5680
5681 if(!p_mgetl(&section_id,f))
5682 {
5683 return false;
5684 }
5685
5686 if(section_id==ID_CSETS)
5687 {
5688 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5689 {
5690 pack_fclose(f);
5691 loadlvlpal(Color);
5692 return true;
5693 }
5694 else
5695 {
5696 pack_fclose(f);
5697 return false;
5698 }
5699 }
5700
5701 return false;
5702 }
5703
5704 bool save_dmaps(const char *path)
5705 {
5706 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5707
5708 if(!f)
5709 {
5710 return false;
5711 }
5712
5713 if(writedmaps(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXDMAPS)==0)
5714 {
5715 pack_fclose(f);
5716 return true;
5717 }
5718
5719 pack_fclose(f);
5720 return false;
5721 }
5722
5723 bool load_dmaps(const char *path, int32_t startdmap)
5724 {
5725 dword section_id;
5726 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5727
5728 if(!f)
5729 {
5730 return false;
5731 }
5732
5733 if(!p_mgetl(&section_id,f))
5734 {
5735 return false;
5736 }
5737
5738 if(section_id==ID_DMAPS)
5739 {
5740 if(readdmaps(f, NULL, 0x250, 33, startdmap, MAXDMAPS-startdmap)==0)
5741 {
5742 pack_fclose(f);
5743 return true;
5744 }
5745 else
5746 {
5747 pack_fclose(f);
5748 return false;
5749 }
5750 }
5751
5752 return false;
5753 }
5754 bool save_combos(const char *path)
5755 {
5756 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5757
5758 if(!f)
5759 {
5760 return false;
5761 }
5762
5763 reset_combo_animations();
5764 reset_combo_animations2();
5765
5766 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)==0)
5767 {
5768 pack_fclose(f);
5769 return true;
5770 }
5771
5772 pack_fclose(f);
5773 return false;
5774 }
5775
5776 bool load_combos(const char *path, int32_t startcombo)
5777 {
5778 dword section_id;
5779 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5780
5781 if(!f)
5782 {
5783 return false;
5784 }
5785
5786 if(!p_mgetl(&section_id,f))
5787 {
5788 return false;
5789 }
5790
5791 if(section_id==ID_COMBOS)
5792 {
5793 if(readcombos(f, NULL, 0x250, 33, startcombo, MAXCOMBOS-startcombo)==0)
5794 {
5795 pack_fclose(f);
5796 return true;
5797 }
5798 else
5799 {
5800 pack_fclose(f);
5801 return false;
5802 }
5803 }
5804
5805 return false;
5806 }
5807
5808 bool save_tiles(const char *path)
5809 {
5810 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5811
5812 if(!f)
5813 {
5814 return false;
5815 }
5816
5817 // reset_combo_animations();
5818 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)==0)
5819 {
5820 pack_fclose(f);
5821 return true;
5822 }
5823
5824 pack_fclose(f);
5825 return false;
5826 }
5827
5828 bool load_tiles(const char *path, int32_t starttile)
5829 {
5830 dword section_id;
5831 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5832
5833 if(!f)
5834 {
5835 return false;
5836 }
5837
5838 if(!p_mgetl(&section_id,f))
5839 {
5840 return false;
5841 }
5842
5843 if(section_id==ID_TILES)
5844 {
5845 if(readtiles(f, newtilebuf, NULL, 0x250, 33, starttile, NEWMAXTILES-starttile, false)==0)
5846 {
5847 pack_fclose(f);
5848 return true;
5849 }
5850 else
5851 {
5852 pack_fclose(f);
5853 init_tiles(true, &header);
5854 return false;
5855 }
5856 }
5857
5858 return false;
5859 }
5860
5861 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5862 bool save_guys(const char *path)
5863 {
5864 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5865
5866 if(!f)
5867 {
5868 return false;
5869 }
5870
5871 /*
5872 int32_t id = ID_GUYS;
5873 if(!p_mputl(id,f))
5874 {
5875 return false;
5876 }
5877 */
5878
5879 zquestheader h;
5880 h.zelda_version = 0x250;
5881 h.build = 21;
5882
5883 if(writeguys(f, &h)==0)
5884 {
5885 pack_fclose(f);
5886 return true;
5887 }
5888
5889 pack_fclose(f);
5890 return false;
5891 }
5892
5893 bool load_guys(const char *path)
5894 {
5895 dword section_id;
5896 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5897
5898 if(!f)
5899 {
5900 return false;
5901 }
5902
5903 if(!p_mgetl(&section_id,f))
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908
5909 zquestheader h;
5910 h.zelda_version = 0x250;
5911 h.build = 21;
5912
5913 if(section_id==ID_GUYS)
5914 {
5915 if(readguys(f, &h)==0)
5916 {
5917 pack_fclose(f);
5918 return true;
5919 }
5920 }
5921
5922 pack_fclose(f);
5923 return false;
5924 }
5925
5926
5927 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5928 bool save_combo_alias(const char *path)
5929 {
5930 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5931
5932 if(!f)
5933 {
5934 return false;
5935 }
5936
5937 zquestheader h;
5938 h.zelda_version = 0x250;
5939 h.build = 21;
5940
5941 if(writecomboaliases(f, 0, 0)==0)
5942 {
5943 pack_fclose(f);
5944 return true;
5945 }
5946
5947 pack_fclose(f);
5948 return false;
5949 }
5950
5951 bool load_combo_alias(const char *path)
5952 {
5953 dword section_id;
5954 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5955
5956 if(!f)
5957 {
5958 return false;
5959 }
5960
5961 if(!p_mgetl(&section_id,f))
5962 {
5963 pack_fclose(f);
5964 return false;
5965 }
5966
5967 zquestheader h;
5968 h.zelda_version = 0x250;
5969 h.build = 21;
5970
5971 if(section_id==ID_COMBOALIASES)
5972 {
5973 if(readcomboaliases(f, &h, 0, 0)==0)
5974 {
5975 pack_fclose(f);
5976 return true;
5977 }
5978 }
5979
5980 pack_fclose(f);
5981 return false;
5982 }
5983
5984 bool load_zgp(const char *path)
5985 {
5986 dword section_id;
5987 dword section_version;
5988 dword section_cversion;
5989 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5990
5991 if(!f)
5992 return false;
5993
5994 if(!p_mgetl(&section_id,f))
5995 {
5996 pack_fclose(f);
5997 return false;
5998 }
5999
6000 if(section_id!=ID_GRAPHICSPACK)
6001 {
6002 pack_fclose(f);
6003 return false;
6004 }
6005
6006 //section version info
6007 if(!p_igetw(&section_version,f))
6008 {
6009 return 2;
6010 }
6011
6012 if(!p_igetw(&section_cversion,f))
6013 {
6014 return 3;
6015 }
6016
6017 //tiles
6018 if(!p_mgetl(&section_id,f))
6019 {
6020 pack_fclose(f);
6021 return false;
6022 }
6023
6024 if(section_id==ID_TILES)
6025 {
6026 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
6027 {
6028 pack_fclose(f);
6029 init_tiles(true, &header);
6030 return false;
6031 }
6032 }
6033 else
6034 {
6035 pack_fclose(f);
6036 return false;
6037 }
6038
6039 //combos
6040 if(!p_mgetl(&section_id,f))
6041 {
6042 pack_fclose(f);
6043 return false;
6044 }
6045
6046 if(section_id==ID_COMBOS)
6047 {
6048 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6049 {
6050 pack_fclose(f);
6051 return false;
6052 }
6053 }
6054 else
6055 {
6056 pack_fclose(f);
6057 return false;
6058 }
6059
6060 //palettes
6061 if(!p_mgetl(&section_id,f))
6062 {
6063 pack_fclose(f);
6064 return false;
6065 }
6066
6067 if(section_id==ID_CSETS)
6068 {
6069 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6070 {
6071 pack_fclose(f);
6072 return false;
6073 }
6074 }
6075 else
6076 {
6077 pack_fclose(f);
6078 return false;
6079 }
6080
6081 //items
6082 if(!p_mgetl(&section_id,f))
6083 {
6084 pack_fclose(f);
6085 return false;
6086 }
6087
6088 if(section_id==ID_ITEMS)
6089 {
6090 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
6091 {
6092 pack_fclose(f);
6093 return false;
6094 }
6095 }
6096 else
6097 {
6098 pack_fclose(f);
6099 return false;
6100 }
6101
6102 //weapons
6103 if(!p_mgetl(&section_id,f))
6104 {
6105 pack_fclose(f);
6106 return false;
6107 }
6108
6109 if(section_id==ID_WEAPONS)
6110 {
6111 if(readweapons(f, &header)!=0)
6112 {
6113 pack_fclose(f);
6114 return false;
6115 }
6116 }
6117 else
6118 {
6119 pack_fclose(f);
6120 return false;
6121 }
6122
6123 //read the triforce pieces info and make sure it worked
6124 //really do this?
6125
6126 //read the game icons info and make sure it worked
6127 if(!p_mgetl(&section_id,f))
6128 {
6129 pack_fclose(f);
6130 return false;
6131 }
6132
6133 if(section_id==ID_ICONS)
6134 {
6135 if(readgameicons(f, &header, &QMisc)!=0)
6136 {
6137 pack_fclose(f);
6138 return false;
6139 }
6140 }
6141 else
6142 {
6143 pack_fclose(f);
6144 return false;
6145 }
6146
6147 //read the misc colors info and map styles info and make sure it worked
6148 if(!p_mgetl(&section_id,f))
6149 {
6150 pack_fclose(f);
6151 return false;
6152 }
6153
6154 if(section_id==ID_COLORS)
6155 {
6156 if(readmisccolors(f, &header, &QMisc)!=0)
6157 {
6158 pack_fclose(f);
6159 return false;
6160 }
6161 }
6162 else
6163 {
6164 pack_fclose(f);
6165 return false;
6166 }
6167
6168 //read the door combo sets and make sure it worked
6169 if(!p_mgetl(&section_id,f))
6170 {
6171 pack_fclose(f);
6172 return false;
6173 }
6174
6175 if(section_id==ID_DOORS)
6176 {
6177 if(readdoorcombosets(f, &header)!=0)
6178 {
6179 pack_fclose(f);
6180 return false;
6181 }
6182 }
6183 else
6184 {
6185 pack_fclose(f);
6186 return false;
6187 }
6188
6189 //read the template screens and make sure it worked
6190 //really do this?
6191
6192 //yay! it worked! close the file and say everything was ok.
6193 loadlvlpal(Color);
6194 setup_combo_animations();
6195 setup_combo_animations2();
6196 pack_fclose(f);
6197 return true;
6198 }
6199
6200 bool save_zgp(const char *path)
6201 {
6202 reset_combo_animations();
6203 reset_combo_animations2();
6204
6205 //open the file
6206 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6207
6208 if(!f)
6209 return false;
6210
6211 dword section_id=ID_GRAPHICSPACK;
6212 dword section_version=V_GRAPHICSPACK;
6213 dword section_cversion=CV_GRAPHICSPACK;
6214
6215 //section id
6216 if(!p_mputl(section_id,f))
6217 {
6218 return 1;
6219 }
6220
6221 //section version info
6222 if(!p_iputw(section_version,f))
6223 {
6224 return 2;
6225 }
6226
6227 if(!p_iputw(section_cversion,f))
6228 {
6229 return 3;
6230 }
6231
6232 //tiles
6233 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6234 {
6235 pack_fclose(f);
6236 return false;
6237 }
6238
6239 //combos
6240 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6241 {
6242 pack_fclose(f);
6243 return false;
6244 }
6245
6246 //palettes
6247 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6248 {
6249 pack_fclose(f);
6250 return false;
6251 }
6252
6253 //items
6254 if(writeitems(f, &header)!=0)
6255 {
6256 pack_fclose(f);
6257 return false;
6258 }
6259
6260 //weapons
6261 if(writeweapons(f, &header)!=0)
6262 {
6263 pack_fclose(f);
6264 return false;
6265 }
6266
6267 //write the triforce pieces info and make sure it worked
6268 //really do this?
6269
6270 //write the game icons info and make sure it worked
6271 if(writegameicons(f, &header)!=0)
6272 {
6273 pack_fclose(f);
6274 return false;
6275 }
6276
6277 //write the misc colors info and map styles info and make sure it worked
6278 if(writemisccolors(f, &header)!=0)
6279 {
6280 pack_fclose(f);
6281 return false;
6282 }
6283
6284 //write the door combo sets and make sure it worked
6285 if(writedoorcombosets(f, &header)!=0)
6286 {
6287 pack_fclose(f);
6288 return false;
6289 }
6290
6291 //write the template screens and make sure it worked
6292 //really do this?
6293
6294 pack_fclose(f);
6295 return true;
6296 }
6297
6298 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6299 {
6300 //open the file
6301 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6302
6303 if(!f)
6304 return false;
6305
6306 dword section_id=ID_SUBSCREEN;
6307 dword s_version=V_SUBSCREEN;
6308 dword s_cversion=CV_SUBSCREEN;
6309
6310 if(!p_mputl(section_id,f))
6311 {
6312 pack_fclose(f);
6313 return false;
6314 }
6315
6316 if(!p_iputw(s_version,f))
6317 {
6318 pack_fclose(f);
6319 return false;
6320 }
6321
6322 if(!p_iputw(s_cversion,f))
6323 {
6324 pack_fclose(f);
6325 return false;
6326 }
6327
6328 if(savefrom.write(f))
6329 {
6330 pack_fclose(f);
6331 return false;
6332 }
6333
6334 pack_fclose(f);
6335 return true;
6336 }
6337
6338 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6339 {
6340 //open the file
6341 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6342
6343 if(!f)
6344 return false;
6345
6346 dword section_id;
6347 dword s_version;
6348 dword s_cversion;
6349
6350 if(!p_mgetl(&section_id,f))
6351 {
6352 pack_fclose(f);
6353 return false;
6354 }
6355
6356 if(section_id!=ID_SUBSCREEN)
6357 {
6358 pack_fclose(f);
6359 return false;
6360 }
6361
6362 if(!p_igetw(&s_version,f))
6363 {
6364 pack_fclose(f);
6365 return false;
6366 }
6367
6368 if(!p_igetw(&s_cversion,f))
6369 {
6370 pack_fclose(f);
6371 return false;
6372 }
6373
6374 if(s_version < 8)
6375 {
6376 subscreen_group g;
6377 memset(&g,0,sizeof(subscreen_group));
6378 if(read_one_old_subscreen(f,&g,s_version)!=0)
6379 {
6380 pack_fclose(f);
6381 return false;
6382 }
6383 if(g.ss_type != loadto.sub_type)
6384 {
6385 pack_fclose(f);
6386 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6387 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6388 return false;
6389 }
6390 loadto.clear();
6391 if(g.objects[0].type != ssoNULL)
6392 loadto.load_old(g);
6393 }
6394 else
6395 {
6396 ZCSubscreen tmp = ZCSubscreen();
6397 if (tmp.read(f, s_version))
6398 {
6399 pack_fclose(f);
6400 return false;
6401 }
6402 if(tmp.sub_type != loadto.sub_type)
6403 {
6404 pack_fclose(f);
6405 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6406 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6407 return false;
6408 }
6409 loadto.clear();
6410 loadto = tmp;
6411 }
6412
6413 pack_fclose(f);
6414 return true;
6415 }
6416
6417 bool setMapCount2(int32_t c)
6418 {
6419 int32_t oldmapcount=map_count;
6420 int32_t currmap=Map.getCurrMap();
6421
6422 bound(c,1,MAXMAPS);
6423 map_count=c;
6424
6425 try
6426 {
6427 TheMaps.resize(c*MAPSCRS);
6428 Map.force_refr_pointer();
6429 map_autolayers.resize(c*6);
6430 }
6431 catch(...)
6432 {
6433 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6434 return false;
6435 }
6436
6437 bound(currmap,0,c-1);
6438 if(map_count>oldmapcount)
6439 {
6440 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6441 {
6442 Map.setCurrMap(mc);
6443
6444 for(int32_t ms=0; ms<MAPSCRS; ms++)
6445 {
6446 Map.clearscr(ms);
6447 }
6448 }
6449 Map.setCurrMap(currmap);
6450 }
6451 else
6452 {
6453 Map.setCurrMap(currmap);
6454 if(!layers_valid(Map.CurrScr()))
6455 fix_layers(Map.CurrScr(), false);
6456
6457 for(int32_t i=0; i<MAXDMAPS; i++)
6458 {
6459 if(DMaps[i].map>=map_count)
6460 {
6461 DMaps[i].map=map_count-1;
6462 }
6463 }
6464 }
6465
6466 return true;
6467 }
6468
6469 extern BITMAP *bmap;
6470
6471 static bool loading_file_new = false;
6472 1 int32_t init_quest()
6473 {
6474 char qstdat_string[2048];
6475 1 strcpy(qstdat_string, "modules/classic/default.qst");
6476
6477 char buf[2048];
6478
6479 1 loading_file_new = true;
6480 1 load_quest(qstdat_string);
6481 1 loading_file_new = false;
6482
6483 1 sprintf(buf,"ZC Editor - Untitled Quest");
6484 1 set_window_title(buf);
6485 1 zinit.last_map = 0;
6486 1 zinit.last_screen = 0;
6487
6488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(bmap != NULL)
6489 {
6490 destroy_bitmap(bmap);
6491 bmap=NULL;
6492 }
6493
6494 1 return 0;
6495 }
6496
6497 void set_questpwd(std::string_view pwd, bool use_keyfile)
6498 {
6499 header.use_keyfile=use_keyfile;
6500
6501 // string_view actually has some quirks that make it less than ideal here.
6502 // It'd probably be best to replace it, but this works for now.
6503 memset(header.password, 0, 256);
6504 strcpy(header.password, pwd.data());
6505 header.dirty_password=true;
6506
6507 cvs_MD5Context ctx;
6508 cvs_MD5Init(&ctx);
6509 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6510 cvs_MD5Final(header.pwd_hash, &ctx);
6511 }
6512
6513
6514 bool is_null_pwd_hash(uint8_t *pwd_hash)
6515 {
6516 cvs_MD5Context ctx;
6517 uint8_t md5sum[16];
6518 char pwd[2]="";
6519
6520 cvs_MD5Init(&ctx);
6521 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6522 cvs_MD5Final(md5sum, &ctx);
6523
6524 return (memcmp(md5sum,pwd_hash,16)==0);
6525 }
6526
6527 static DIALOG pwd_dlg[] =
6528 {
6529 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6530 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6531 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6532 // 2 (filename)
6533 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6534 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6535 // 4 (challenge hash)
6536 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6537 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6538 // 6 (password)
6539 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6540 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6541 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6542 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6543 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6544 };
6545
6546 int32_t reverse_string(char* str)
6547 {
6548
6549 if(NULL==str)
6550 {
6551 return -1; //no string
6552 }
6553
6554 int32_t l=(int32_t)strlen(str)-1; //get the string length
6555
6556 if(1==l)
6557 {
6558 return 1;
6559 }
6560
6561 char c;
6562
6563 for(int32_t x=0; x < l; x++,l--)
6564 {
6565 c = str[x];
6566 str[x] = str[l];
6567 str[l] = c;
6568 }
6569
6570 return 0;
6571 }
6572
6573 #ifdef __GNUC__
6574 #pragma GCC diagnostic push
6575 #pragma GCC diagnostic ignored "-Wunreachable-code"
6576 #endif
6577
6578 9 int32_t quest_access(const char *filename, zquestheader *hdr)
6579 {
6580
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (is_headless())
6581 9 return 1;
6582
6583 #ifdef __EMSCRIPTEN__
6584 return 1;
6585 #endif
6586
6587 //Protection against compiling a release version with password protection off.
6588 static bool passguard = false;
6589
6590 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6591 #define MUST_HAVE_PASSWORD
6592 passguard = true;
6593 #endif
6594
6595 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6596 #if (defined _MSC_VER || defined _NPASS)
6597 return 1;
6598 #endif
6599 #endif
6600 if(devpwd()) return 1;
6601
6602 char hash_string[33];
6603
6604 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6605 {
6606 return 1;
6607 }
6608
6609 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6610 return true;
6611
6612 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6613 pwd_dlg[2].dp=get_filename(filename);
6614 cvs_MD5Context ctx;
6615 uint8_t md5sum[16]={0};
6616 char response[33]="";
6617 char prompt[256]="";
6618
6619 memcpy(md5sum, hdr->pwd_hash, 16);
6620
6621 for(int32_t i=0; i<300; ++i)
6622 {
6623 for(int32_t j=0; j<16; ++j)
6624 {
6625 sprintf(response+j*2, "%02x", md5sum[j]);
6626 }
6627
6628 if(i&1)
6629 {
6630 reverse_string(response);
6631 }
6632
6633 if(i==149)
6634 {
6635 strcpy(hash_string, response);
6636 }
6637
6638 cvs_MD5Init(&ctx);
6639 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6640 cvs_MD5Final(md5sum, &ctx);
6641 }
6642
6643 pwd_dlg[4].dp=hash_string;
6644
6645 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6646 {
6647 sprintf(prompt,"%s",response);
6648 }
6649
6650 pwd_dlg[6].dp=prompt;
6651
6652 large_dialog(pwd_dlg);
6653
6654 int32_t cancel = do_zqdialog(pwd_dlg,6);
6655
6656 if(cancel == 8)
6657 return 2;
6658
6659 bool ret=check_questpwd(hdr, prompt);
6660
6661 if(!ret)
6662 {
6663 ret=(strcmp(response,prompt)==0);
6664 }
6665 return ret ? 1 : 0;
6666 9 }
6667
6668 void set_rules(byte* newrules);
6669 8 void popup_bugfix_dlg(const char* cfg)
6670 {
6671 8 bool dont_show_again = zc_get_config("zquest",cfg,0);
6672
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(!dont_show_again && hasCompatRulesEnabled())
6673 {
6674
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 AlertDialog("Apply New Bugfixes",
6675
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 "New bugfixes found that can be applied to this quest!"
6676 "\nWould you like to apply them?"
6677 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6678 8 [&](bool ret,bool dsa)
6679 {
6680 if(ret)
6681 {
6682 applyRuleTemplate(ruletemplateFixCompat);
6683 }
6684 if(dsa)
6685 {
6686 zc_set_config("zquest",cfg,1);
6687 }
6688 },
6689
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 "Yes","No",
6690 0,false, //timeout - none
6691 true //"Don't show this again"
6692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ).show();
6693 8 }
6694 8 }
6695
6696 #ifdef __GNUC__
6697 #pragma GCC diagnostic pop
6698 #endif
6699
6700 // wrapper to reinitialize everything on an error
6701 9 int32_t load_quest(const char *filename, bool show_progress)
6702 {
6703 char buf[2048];
6704 // if(encrypted)
6705 // setPackfilePassword(datapwd);
6706 byte skip_flags[4];
6707
6708
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for(int32_t i=0; i<4; ++i)
6709 {
6710 36 skip_flags[i]=0;
6711 36 }
6712
2/2
✓ Branch 0 taken 6219 times.
✓ Branch 1 taken 9 times.
6228 for(int32_t i=0; i<qr_MAX; i++)
6713 6219 set_qr(i,0);
6714 9 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags);
6715
6716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret!=qe_OK)
6717 {
6718 init_quest();
6719 }
6720 else
6721 {
6722 9 int32_t accessret = quest_access(filename, &header);
6723
6724
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(accessret != 1)
6725 {
6726 init_quest();
6727
6728 if(accessret == 0)
6729 ret=qe_pwd;
6730 else
6731 ret=qe_cancel;
6732 }
6733 else
6734 {
6735 9 Map.clear();
6736 9 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6737 9 Map.setCurrScr(zinit.last_screen);
6738 extern int32_t current_mappage;
6739 9 current_mappage = 0;
6740 9 bool found_default = false;
6741
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6742 {
6743 65 auto &pg = map_page[q];
6744
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9 times.
65 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6745 {
6746 2 current_mappage = q;
6747 2 break;
6748 }
6749
4/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
63 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6750 56 continue;
6751 else
6752 {
6753 7 current_mappage = q;
6754 7 found_default = true;
6755 }
6756 7 }
6757 9 refresh(rALL);
6758 9 refresh_pal();
6759 9 set_rules(quest_rules);
6760 9 saved = true;
6761
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
9 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6762 8 popup_bugfix_dlg("dsa_compatrule");
6763
6764
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(bmap != NULL)
6765 {
6766 destroy_bitmap(bmap);
6767 bmap=NULL;
6768 }
6769
6770
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (show_progress)
6771 {
6772 1 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6773 1 set_window_title(buf);
6774 1 }
6775 }
6776 }
6777
6778 9 Map.ClearCommandHistory();
6779
6780 9 return ret;
6781 }
6782
6783 int32_t load_tileset(const char *filename, dword tsetflags)
6784 {
6785 char buf[2048];
6786 byte skip_flags[4];
6787
6788 for(int32_t i=0; i<4; ++i)
6789 skip_flags[i]=0;
6790 for(int32_t i=0; i<qr_MAX; i++)
6791 set_qr(i,0);
6792 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6793
6794 if(ret!=qe_OK)
6795 init_quest();
6796 else
6797 {
6798 int32_t accessret = quest_access(filename, &header);
6799
6800 if(accessret != 1)
6801 {
6802 init_quest();
6803
6804 if(accessret == 0)
6805 ret=qe_pwd;
6806 else
6807 ret=qe_cancel;
6808 }
6809 else
6810 {
6811 Map.clear();
6812 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6813 Map.setCurrScr(zinit.last_screen);
6814 extern int32_t current_mappage;
6815 current_mappage = 0;
6816 bool found_default = false;
6817 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6818 {
6819 auto &pg = map_page[q];
6820 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6821 {
6822 current_mappage = q;
6823 break;
6824 }
6825 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6826 continue;
6827 else
6828 {
6829 current_mappage = q;
6830 found_default = true;
6831 }
6832 }
6833 refresh(rALL);
6834 refresh_pal();
6835 set_rules(quest_rules);
6836 if(!zc_get_config("zquest","auto_filenew_bugfixes",1))
6837 popup_bugfix_dlg("dsa_compatrule");
6838
6839 if(bmap != NULL)
6840 {
6841 destroy_bitmap(bmap);
6842 bmap=NULL;
6843 }
6844
6845 set_window_title("ZC Editor - Untitled Quest");
6846 first_save = saved = false;
6847 memset(filepath,0,255);
6848 memset(temppath,0,255);
6849 }
6850 }
6851
6852 Map.ClearCommandHistory();
6853
6854 return ret;
6855 }
6856
6857 60 bool write_midi(MIDI *m,PACKFILE *f)
6858 {
6859 int32_t c;
6860
6861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if(!p_mputw(m->divisions,f)) return false;
6862
6863
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 60 times.
1980 for(c=0; c<MIDI_TRACKS; c++)
6864 {
6865
1/2
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
1920 if(!p_mputl(m->track[c].len,f)) return false;
6866
6867
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 492 times.
1920 if(m->track[c].len > 0)
6868 {
6869
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6870 return false;
6871 492 }
6872 1920 }
6873
6874 60 return true;
6875 60 }
6876
6877 bool write_music(int32_t format, MIDI* m, PACKFILE *f)
6878 {
6879 // format - data format (midi, nsf, ...)
6880 // m - pointer to data.
6881
6882 int32_t c;
6883
6884 switch(format)
6885 {
6886 case MFORMAT_MIDI:
6887
6888 if(!p_mputw(m->divisions,f)) return false;
6889
6890 for(c=0; c<MIDI_TRACKS; c++)
6891 {
6892 if(!p_mputl(m->track[c].len,f)) return false;
6893
6894 if(m->track[c].len > 0)
6895 {
6896 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6897 return false;
6898 }
6899 }
6900
6901 break;
6902
6903 case MFORMAT_NSF:
6904
6905 break;
6906
6907 default:
6908 return false;
6909 break;
6910 }
6911
6912 return true;
6913 }
6914
6915 6 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6916 {
6917 6 dword section_id=ID_HEADER;
6918 6 dword section_version=V_HEADER;
6919 6 dword section_cversion=CV_HEADER;
6920 6 dword section_size=0;
6921
6922 //file header string
6923
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6924 {
6925 new_return(1);
6926 }
6927
6928 //section id
6929
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
6930 {
6931 new_return(2);
6932 }
6933
6934 //section version info
6935
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
6936 {
6937 new_return(3);
6938 }
6939
6940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
6941 {
6942 new_return(4);
6943 }
6944
6945
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6946 {
6947 12 fake_pack_writing=(writecycle==0);
6948
6949 //section size
6950
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
6951 {
6952 new_return(5);
6953 }
6954
6955 12 writesize=0;
6956
6957 //finally... section data
6958
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->zelda_version,f))
6959 {
6960 new_return(6);
6961 }
6962
6963
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->build,f))
6964 {
6965 new_return(7);
6966 }
6967
6968
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6969 {
6970 new_return(8);
6971 }
6972
6973
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->internal,f))
6974 {
6975 new_return(10);
6976 }
6977
6978
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->quest_number,f))
6979 {
6980 new_return(11);
6981 }
6982
6983
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->version,16,f))
6984 {
6985 new_return(12);
6986 }
6987
6988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->minver,16,f))
6989 {
6990 new_return(13);
6991 }
6992
6993
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->title,sizeof(Header->title),f))
6994 {
6995 new_return(14);
6996 }
6997
6998
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->author,sizeof(Header->author),f))
6999 {
7000 new_return(15);
7001 }
7002
7003
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->use_keyfile,f))
7004 {
7005 new_return(16);
7006 }
7007
7008
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
7009 {
7010 new_return(17);
7011 }
7012
7013
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
7014 {
7015 new_return(19);
7016 }
7017
7018
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(0,f)) //why are we doing this?
7019 //this is for map count, it seems. -Z
7020 {
7021 new_return(20);
7022 }
7023
7024 12 auto version = getVersion();
7025
7026
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.major,f))
7027 {
7028 new_return(21);
7029 }
7030
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.minor,f))
7031 {
7032 new_return(22);
7033 }
7034
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.patch,f))
7035 {
7036 new_return(23);
7037 }
7038 // Fourth component is deprecated.
7039
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7040 {
7041 new_return(24);
7042 }
7043
7044 // Numerous prerelease stages is deprecated.
7045
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7046 {
7047 new_return(25);
7048 }
7049
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7050 {
7051 new_return(26);
7052 }
7053
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7054 {
7055 new_return(27);
7056 }
7057
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7058 {
7059 new_return(28);
7060 }
7061
7062
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(BUILDTM_YEAR,f))
7063 {
7064 new_return(29);
7065 }
7066
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MONTH,f))
7067 {
7068 new_return(30);
7069 }
7070
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_DAY,f))
7071 {
7072 new_return(31);
7073 }
7074
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_HOUR,f))
7075 {
7076 new_return(32);
7077 }
7078
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MINUTE,f))
7079 {
7080 new_return(33);
7081 }
7082
7083
7084
7085 char tempsig[256];
7086 12 memset(tempsig, 0, 256);
7087 12 strcpy(tempsig, DEV_SIGNOFF);
7088
7089
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempsig,256,f))
7090 {
7091 new_return(34);
7092 }
7093
7094 char tempcompilersig[256];
7095 12 memset(tempcompilersig, 0, 256);
7096 12 strcpy(tempcompilersig, COMPILER_NAME);
7097
7098
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilersig,256,f))
7099 {
7100 new_return(35);
7101 }
7102
7103 char tempcompilerversion[256];
7104 12 memset(tempcompilerversion, 0, 256);
7105 #ifdef _MSC_VER
7106 zc_itoa(_MSC_VER,tempcompilerversion,10);
7107 #else
7108 12 strcpy(tempcompilerversion, COMPILER_VERSION);
7109 #endif
7110
7111
7112
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilerversion,256,f))
7113 {
7114 new_return(36);
7115 }
7116
7117
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite("ZQuest Classic",1024,f))
7118 {
7119 new_return(37);
7120 }
7121
7122
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(V_ZC_COMPILERSIG,f))
7123 {
7124 new_return(38);
7125 }
7126 #ifdef _MSC_VER
7127 if(!p_iputl((_MSC_VER / 100),f))
7128 {
7129 new_return(39);
7130 }
7131 #else
7132
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FIRST,f))
7133 {
7134 new_return(39);
7135 }
7136 #endif
7137
7138
7139
7140 #ifdef _MSC_VER
7141 if(!p_iputl((_MSC_VER % 100),f))
7142 {
7143 new_return(41);
7144 }
7145 #else
7146
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_SECOND,f))
7147 {
7148 new_return(41);
7149 }
7150 #endif
7151
7152 #ifdef _MSC_VER
7153 # if _MSC_VER >= 1400
7154 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7155 {
7156 new_return(40);
7157 }
7158 # else
7159 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7160 {
7161 new_return(40);
7162 }
7163 #endif
7164 #else
7165
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_THIRD,f))
7166 {
7167 new_return(40);
7168 }
7169 #endif
7170
7171 #ifdef _MSC_VER
7172 if(!p_iputl((_MSC_BUILD),f))
7173 {
7174 new_return(42);
7175 }
7176 #else
7177
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FOURTH,f))
7178 {
7179 new_return(42);
7180 }
7181 #endif
7182
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7183 {
7184 new_return(43);
7185 }
7186
7187 char tempmodulename[1024];
7188 12 memset(tempmodulename, 0, 1024);
7189 12 strcpy(tempmodulename, moduledata.module_name);
7190
7191
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempmodulename,1024,f))
7192 {
7193 new_return(44);
7194 }
7195
7196 char tempdate[256];
7197 12 memset(tempdate, 0, 256);
7198 12 strcpy(tempdate, __DATE__);
7199
7200
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempdate,256,f))
7201 {
7202 new_return(45);
7203 }
7204 char temptime[256];
7205 12 memset(temptime, 0, 256);
7206 12 strcpy(temptime, __TIME__);
7207
7208
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptime,256,f))
7209 {
7210 new_return(46);
7211 }
7212
7213
7214 char temptimezone[6];
7215 12 memset(temptimezone, 0, 6);
7216 12 strcpy(temptimezone, __TIMEZONE__);
7217
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptimezone,6,f))
7218 {
7219 new_return(47);
7220 }
7221
7222
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7223 {
7224 new_return(48);
7225 }
7226
7227
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(isStableRelease() ? 0 : 1, f))
7228 {
7229 new_return(49);
7230 }
7231
7232
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if(!p_putcstr(version.version_string, f))
7233 {
7234 new_return(50);
7235 }
7236
7237
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7238 {
7239 6 section_size=writesize;
7240 6 }
7241 12 }
7242
7243
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7244 {
7245 char ebuf[80];
7246 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7247 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7248 }
7249
7250 6 new_return(0);
7251 }
7252
7253 6 int32_t writerules(PACKFILE *f, zquestheader *Header)
7254 {
7255 //these are here to bypass compiler warnings about unused arguments
7256 6 Header=Header;
7257
7258 6 dword section_id=ID_RULES;
7259 6 dword section_version=V_RULES;
7260 6 dword section_cversion=CV_RULES;
7261 6 dword section_size=0;
7262
7263 //section id
7264
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7265 {
7266 new_return(1);
7267 }
7268
7269 //section version info
7270
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7271 {
7272 new_return(2);
7273 }
7274
7275
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
7276 {
7277 new_return(3);
7278 }
7279
7280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl(V_COMPATRULE,f))
7281 {
7282 new_return(6);
7283 }
7284
7285
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7286 {
7287 12 fake_pack_writing=(writecycle==0);
7288
7289 //section size
7290
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7291 {
7292 new_return(4);
7293 }
7294
7295 12 writesize=0;
7296
7297 //finally... section data
7298
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7299 {
7300 new_return(5);
7301 }
7302
7303
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7304 {
7305 6 section_size=writesize;
7306 6 }
7307 12 }
7308
7309
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7310 {
7311 char ebuf[80];
7312 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7313 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7314 }
7315
7316 6 new_return(0);
7317 }
7318
7319
7320 6 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7321 {
7322 //these are here to bypass compiler warnings about unused arguments
7323 6 Header=Header;
7324
7325 6 dword section_id=ID_DOORS;
7326 6 dword section_version=V_DOORS;
7327 6 dword section_cversion=CV_DOORS;
7328 6 dword section_size=0;
7329
7330 //section id
7331
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7332 {
7333 new_return(1);
7334 }
7335
7336 //section version info
7337
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7338 {
7339 new_return(2);
7340 }
7341
7342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7343 {
7344 new_return(3);
7345 }
7346
7347
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7348 {
7349 12 fake_pack_writing=(writecycle==0);
7350
7351 //section size
7352
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7353 {
7354 new_return(4);
7355 }
7356
7357 12 writesize=0;
7358
7359 //finally... section data
7360
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(door_combo_set_count,f))
7361 {
7362 new_return(5);
7363 }
7364
7365
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 12 times.
176 for(int32_t i=0; i<door_combo_set_count; i++)
7366 {
7367 //name
7368
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
164 if(!pfwrite(&DoorComboSets[i].name,sizeof(DoorComboSets[0].name),f))
7369 {
7370 new_return(6);
7371 }
7372
7373 //up door
7374
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7375 {
7376
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7377 {
7378
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7379 {
7380 new_return(7);
7381 }
7382 5904 }
7383 1476 }
7384
7385
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7386 {
7387
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7388 {
7389
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7390 {
7391 new_return(8);
7392 }
7393 5904 }
7394 1476 }
7395
7396 //down door
7397
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7398 {
7399
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7400 {
7401
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7402 {
7403 new_return(9);
7404 }
7405 5904 }
7406 1476 }
7407
7408
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7409 {
7410
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7411 {
7412
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7413 {
7414 new_return(10);
7415 }
7416 5904 }
7417 1476 }
7418
7419
7420 //left door
7421
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7422 {
7423
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7424 {
7425
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7426
7427 {
7428 new_return(11);
7429 }
7430 8856 }
7431 1476 }
7432
7433
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7434 {
7435
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7436 {
7437
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7438 {
7439 new_return(12);
7440 }
7441 8856 }
7442 1476 }
7443
7444 //right door
7445
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7446 {
7447
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7448 {
7449
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7450 {
7451 new_return(13);
7452 }
7453 8856 }
7454 1476 }
7455
7456
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7457 {
7458
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7459 {
7460
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7461 {
7462 new_return(14);
7463 }
7464 8856 }
7465 1476 }
7466
7467
7468 //up bomb rubble
7469
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7470 {
7471
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7472 {
7473 new_return(15);
7474 }
7475 328 }
7476
7477
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7478 {
7479
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7480 {
7481 new_return(16);
7482 }
7483 328 }
7484
7485 //down bomb rubble
7486
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7487 {
7488
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7489 {
7490 new_return(17);
7491 }
7492 328 }
7493
7494
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7495 {
7496
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7497 {
7498 new_return(18);
7499 }
7500 328 }
7501
7502 //left bomb rubble
7503
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7504 {
7505
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7506 {
7507 new_return(19);
7508 }
7509 492 }
7510
7511
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7512 {
7513
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7514 {
7515 new_return(20);
7516 }
7517 492 }
7518
7519 //right bomb rubble
7520
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7521 {
7522
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7523 {
7524 new_return(21);
7525 }
7526 492 }
7527
7528
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7529 {
7530
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7531 {
7532 new_return(22);
7533 }
7534 492 }
7535
7536 //walkthrough stuff
7537
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7538 {
7539
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7540 {
7541 new_return(23);
7542 }
7543 656 }
7544
7545
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7546 {
7547
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7548 {
7549 new_return(24);
7550 }
7551 656 }
7552
7553 //flags
7554
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7555 {
7556
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].flags[j],f))
7557 {
7558 new_return(25);
7559 }
7560 328 }
7561 164 }
7562
7563
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7564 {
7565 6 section_size=writesize;
7566 6 }
7567 12 }
7568
7569
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7570 {
7571 char ebuf[80];
7572 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7573 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7574 }
7575
7576 6 new_return(0);
7577 }
7578
7579 6 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7580 {
7581 //these are here to bypass compiler warnings about unused arguments
7582 6 version=version;
7583 6 build=build;
7584
7585 6 word dmap_count=count_dmaps();
7586 6 dword section_id=ID_DMAPS;
7587 6 dword section_version=V_DMAPS;
7588 6 dword section_cversion=CV_DMAPS;
7589 6 dword section_size=0;
7590
7591 //section id
7592
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7593 {
7594 new_return(1);
7595 }
7596
7597 //section version info
7598
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7599 {
7600 new_return(2);
7601 }
7602
7603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7604 {
7605 new_return(3);
7606 }
7607
7608
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7609 {
7610 12 fake_pack_writing=(writecycle==0);
7611
7612 //section size
7613
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7614 {
7615 new_return(4);
7616 }
7617
7618 12 writesize=0;
7619
7620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, max_dmaps);
7621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7622
7623 //finally... section data
7624
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(dmap_count,f))
7625 {
7626 new_return(5);
7627 }
7628
7629
7630
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7631 {
7632 6144 DMaps[i].validate_subscreens();
7633
7634
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].map,f))
7635 {
7636 new_return(6);
7637 }
7638
7639
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].level,f))
7640 {
7641 new_return(7);
7642 }
7643
7644
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].xoff,f))
7645 {
7646 new_return(8);
7647 }
7648
7649
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].compass,f))
7650 {
7651 new_return(9);
7652 }
7653
7654
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].color,f))
7655 {
7656 new_return(10);
7657 }
7658
7659
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].midi,f))
7660 {
7661 new_return(11);
7662 }
7663
7664
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].cont,f))
7665 {
7666 new_return(12);
7667 }
7668
7669
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].type,f))
7670 {
7671 new_return(13);
7672 }
7673
7674
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7675 {
7676
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(DMaps[i].grid[j],f))
7677 {
7678 new_return(14);
7679 }
7680 49152 }
7681
7682
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7683 {
7684 new_return(15);
7685 }
7686
7687
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putwstr(DMaps[i].title,f))
7688 {
7689 new_return(16);
7690 }
7691
7692
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7693 {
7694 new_return(17);
7695 }
7696
7697
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7698 {
7699 new_return(18);
7700 }
7701
7702
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_1_cset,f))
7703 {
7704 new_return(19);
7705 }
7706
7707
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7708 {
7709 new_return(20);
7710 }
7711
7712
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_2_cset,f))
7713 {
7714 new_return(21);
7715 }
7716
7717
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7718 {
7719 new_return(22);
7720 }
7721
7722
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_1_cset,f))
7723 {
7724 new_return(23);
7725 }
7726
7727
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7728 {
7729 new_return(24);
7730 }
7731
7732
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_2_cset,f))
7733 {
7734 new_return(25);
7735 }
7736
7737
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7738 {
7739 new_return(26);
7740 }
7741
7742
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].tmusictrack,f))
7743 {
7744 new_return(25);
7745 }
7746
7747
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].active_subscreen,f))
7748 {
7749 new_return(26);
7750 }
7751
7752
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].passive_subscreen,f))
7753 {
7754 new_return(27);
7755 }
7756
7757 byte disabled[32];
7758 6144 memset(disabled,0,32);
7759
7760
2/2
✓ Branch 0 taken 1572864 times.
✓ Branch 1 taken 6144 times.
1579008 for(int32_t j=0; j<MAXITEMS; j++)
7761 {
7762
1/2
✓ Branch 0 taken 1572864 times.
✗ Branch 1 not taken.
1572864 if(DMaps[i].disableditems[j])
7763 {
7764 disabled[j/8] |= (1 << (j%8));
7765 }
7766 1572864 }
7767
7768
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(disabled,32,f))
7769 {
7770 new_return(28);
7771 }
7772
7773
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].flags,f))
7774 {
7775 new_return(29);
7776 }
7777
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].sideview,f))
7778 {
7779 new_return(30);
7780 }
7781
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].script,f))
7782 {
7783 new_return(31);
7784 }
7785
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7786 {
7787
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].initD[q],f))
7788 {
7789 new_return(32);
7790 }
7791
7792 49152 }
7793
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7794 {
7795
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
7796 {
7797
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if (!p_putc(DMaps[i].initD_label[q][w],f))
7798 {
7799 new_return(33);
7800 }
7801 3194880 }
7802 49152 }
7803
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].active_sub_script,f))
7804 {
7805 new_return(34);
7806 }
7807
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].passive_sub_script,f))
7808 {
7809 new_return(35);
7810 }
7811
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7812 {
7813
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].sub_initD[q],f))
7814 {
7815 new_return(36);
7816 }
7817 49152 }
7818
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7819 {
7820
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7821 {
7822
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7823 {
7824 new_return(37);
7825 }
7826 3194880 }
7827 49152 }
7828
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].onmap_script,f))
7829 {
7830 new_return(38);
7831 }
7832
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7833 {
7834
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7835 {
7836 new_return(39);
7837 }
7838 49152 }
7839
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7840 {
7841
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7842 {
7843
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7844 {
7845 new_return(40);
7846 }
7847 3194880 }
7848 49152 }
7849
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].mirrorDMap,f))
7850 {
7851 new_return(41);
7852 }
7853
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7854 {
7855 new_return(42);
7856 }
7857
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7858 {
7859 new_return(43);
7860 }
7861
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7862 {
7863 new_return(44);
7864 }
7865
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7866 {
7867 new_return(45);
7868 }
7869
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].overlay_subscreen, f))
7870 new_return(46);
7871
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].intro_string_id, f))
7872 new_return(47);
7873
7874 // Reserved for z3.
7875
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7876 {
7877
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 393216 times.
442368 for(int32_t k=0; k<8; k++)
7878 {
7879
1/2
✓ Branch 0 taken 393216 times.
✗ Branch 1 not taken.
393216 if(!p_putc(0,f))
7880 {
7881 new_return(48);
7882 }
7883 393216 }
7884 49152 }
7885 6144 }
7886
7887
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7888 {
7889 6 section_size=writesize;
7890 6 }
7891 12 }
7892
7893
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7894 {
7895 char ebuf[80];
7896 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7897 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7898 }
7899
7900 6 new_return(0);
7901 }
7902
7903 6 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7904 {
7905 //these are here to bypass compiler warnings about unused arguments
7906 6 Header=Header;
7907
7908 6 dword section_id=ID_COLORS;
7909 6 dword section_version=V_COLORS;
7910 6 dword section_cversion=CV_COLORS;
7911 6 dword section_size = 0;
7912
7913 //section id
7914
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7915 {
7916 new_return(1);
7917 }
7918
7919
7920 //section version info
7921
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7922 {
7923 new_return(2);
7924 }
7925
7926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7927 {
7928 new_return(3);
7929 }
7930
7931
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7932 {
7933 12 fake_pack_writing=(writecycle==0);
7934
7935 //section size
7936
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7937 {
7938 new_return(4);
7939 }
7940
7941 12 writesize=0;
7942
7943
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.text,f))
7944 {
7945 new_return(5);
7946 }
7947
7948
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.caption,f))
7949 {
7950 new_return(6);
7951 }
7952
7953
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overw_bg,f))
7954 {
7955 new_return(7);
7956 }
7957
7958
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_bg,f))
7959 {
7960 new_return(8);
7961 }
7962
7963
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_fg,f))
7964 {
7965 new_return(9);
7966 }
7967
7968
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.cave_fg,f))
7969 {
7970 new_return(10);
7971 }
7972
7973
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_dk,f))
7974 {
7975 new_return(11);
7976 }
7977
7978
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_goal,f))
7979 {
7980 new_return(12);
7981 }
7982
7983
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_lt,f))
7984 {
7985 new_return(13);
7986 }
7987
7988
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_dk,f))
7989 {
7990 new_return(14);
7991 }
7992
7993
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_bg,f))
7994 {
7995 new_return(15);
7996 }
7997
7998
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_color,f))
7999 {
8000 new_return(16);
8001 }
8002
8003
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.hero_dot,f))
8004 {
8005 new_return(17);
8006 }
8007
8008
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_bg,f))
8009 {
8010 new_return(18);
8011 }
8012
8013
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_fg,f))
8014 {
8015 new_return(19);
8016 }
8017
8018
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triforce_cset,f))
8019 {
8020 new_return(20);
8021 }
8022
8023
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_cset,f))
8024 {
8025 new_return(21);
8026 }
8027
8028
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overworld_map_cset,f))
8029 {
8030 new_return(22);
8031 }
8032
8033
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
8034 {
8035 new_return(23);
8036 }
8037
8038
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.blueframe_cset,f))
8039 {
8040 new_return(24);
8041 }
8042
8043
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.HCpieces_cset,f))
8044 {
8045 new_return(31);
8046 }
8047
8048
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_shadow,f))
8049 {
8050 new_return(32);
8051 }
8052
8053
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.msgtext,f))
8054 {
8055 new_return(33);
8056 }
8057
8058
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triforce_tile,f))
8059 {
8060 new_return(34);
8061 }
8062
8063
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triframe_tile,f))
8064 {
8065 new_return(35);
8066 }
8067
8068
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
8069 {
8070 new_return(36);
8071 }
8072
8073
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
8074 {
8075 new_return(37);
8076 }
8077
8078
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.blueframe_tile,f))
8079 {
8080 new_return(38);
8081 }
8082
8083
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
8084 {
8085 new_return(39);
8086 }
8087
8088
8089
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8090 {
8091 6 section_size=writesize;
8092 6 }
8093 12 }
8094
8095
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8096 {
8097 char ebuf[80];
8098 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8099 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8100 }
8101
8102 6 new_return(0);
8103 }
8104
8105 6 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
8106 {
8107 //these are here to bypass compiler warnings about unused arguments
8108 6 Header=Header;
8109
8110 6 dword section_id=ID_ICONS;
8111 6 dword section_version=V_ICONS;
8112 6 dword section_cversion=CV_ICONS;
8113 6 dword section_size = 0;
8114
8115 //section id
8116
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8117 {
8118 new_return(1);
8119 }
8120
8121 //section version info
8122
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8123 {
8124 new_return(2);
8125 }
8126
8127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8128 {
8129 new_return(3);
8130 }
8131
8132
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8133 {
8134 12 fake_pack_writing=(writecycle==0);
8135
8136 //section size
8137
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8138 {
8139 new_return(4);
8140 }
8141
8142 12 writesize=0;
8143
8144
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
8145 {
8146
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(QMisc.icons[i],f))
8147 {
8148 new_return(5);
8149 }
8150 48 }
8151
8152
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8153 {
8154 6 section_size=writesize;
8155 6 }
8156 12 }
8157
8158
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8159 {
8160 char ebuf[80];
8161 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8162 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8163 }
8164
8165 6 new_return(0);
8166 }
8167
8168 6 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8169 {
8170 //these are here to bypass compiler warnings about unused arguments
8171 6 Header=Header;
8172
8173 6 dword section_id=ID_MISC;
8174 6 dword section_version=V_MISC;
8175 6 dword section_cversion=CV_MISC;
8176 6 word shops=count_shops(&QMisc);
8177 6 word infos=count_infos(&QMisc);
8178 6 word warprings=count_warprings(&QMisc);
8179 6 word triforces=8;
8180 6 dword section_size = 0;
8181
8182 //section id
8183
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8184 {
8185 new_return(1);
8186 }
8187
8188
8189 //section version info
8190
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8191 {
8192 new_return(2);
8193 }
8194
8195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8196 {
8197 new_return(3);
8198 }
8199
8200
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8201 {
8202 12 fake_pack_writing=(writecycle==0);
8203
8204 //section size
8205
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8206 {
8207 new_return(4);
8208 }
8209
8210 12 writesize=0;
8211
8212 //shops
8213
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(shops,f))
8214 {
8215 new_return(5);
8216 }
8217
8218
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8219 {
8220
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8221 {
8222 new_return(6);
8223 }
8224
8225
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8226 {
8227
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].item[j],f))
8228 {
8229 new_return(7);
8230 }
8231 384 }
8232
8233
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8234 {
8235
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].price[j],f))
8236 {
8237 new_return(8);
8238 }
8239 384 }
8240
8241
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8242 {
8243
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8244 {
8245 new_return(9);
8246 }
8247 384 }
8248 128 }
8249
8250 //infos
8251
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(infos,f))
8252 {
8253 new_return(10);
8254 }
8255
8256
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<infos; i++)
8257 {
8258
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8259 {
8260 new_return(11);
8261 }
8262
8263
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8264 {
8265
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].str[j],f))
8266 {
8267 new_return(12);
8268 }
8269 384 }
8270
8271
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8272 {
8273
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].price[j],f))
8274 {
8275 new_return(13);
8276 }
8277 384 }
8278 128 }
8279
8280 //warp rings
8281
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(warprings,f))
8282 {
8283 new_return(14);
8284 }
8285
8286
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
156 for(int32_t i=0; i<warprings; i++)
8287 {
8288
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8289 {
8290
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8291 {
8292 new_return(15);
8293 }
8294 1296 }
8295
8296
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8297 {
8298
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_putc(QMisc.warp[i].scr[j],f))
8299 {
8300 new_return(16);
8301 }
8302 1296 }
8303
8304
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.warp[i].size,f))
8305 {
8306 new_return(17);
8307 }
8308 144 }
8309
8310 //triforce pieces
8311
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<triforces; i++)
8312 {
8313
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(!p_putc(QMisc.triforce[i],f))
8314 {
8315 new_return(18);
8316 }
8317 96 }
8318
8319 //end string
8320
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(QMisc.endstring,f))
8321 {
8322 new_return(19);
8323 }
8324
8325 //V_MISC >= 8
8326
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8327 {
8328
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8329 {
8330
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].str[j],f))
8331 {
8332 new_return(20);
8333 }
8334 384 }
8335 128 }
8336 //V_MISC >= 9
8337
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8338 {
8339
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputl(QMisc.questmisc[q],f))
8340 new_return(21);
8341 384 }
8342
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8343 {
8344
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 384 times.
49536 for ( int32_t j = 0; j < 128; j++ )
8345
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(QMisc.questmisc_strings[q][j],f))
8346 new_return(22);
8347 384 }
8348 //V_MISC >= 11
8349
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8350 new_return(23);
8351
8352 //V_MISC >= 12
8353
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sprMAX; ++q)
8354 {
8355
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.sprites[q],f))
8356 new_return(24);
8357 3072 }
8358
8359 //V_MISC >= 13
8360
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(size_t q = 0; q < 64; ++q)
8361 {
8362 768 bottletype* bt = &(QMisc.bottle_types[q]);
8363
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!pfwrite(bt->name, 32, f))
8364 new_return(25);
8365
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 768 times.
3072 for(size_t j = 0; j < 3; ++j)
8366 {
8367
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_putc(bt->counter[j], f))
8368 new_return(25);
8369
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_iputw(bt->amount[j], f))
8370 new_return(25);
8371 2304 }
8372
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->flags, f))
8373 new_return(25);
8374
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->next_type, f))
8375 new_return(25);
8376 768 }
8377
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(size_t q = 0; q < 256; ++q)
8378 {
8379 3072 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8380
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if (!pfwrite(bst->name, 32, f))
8381 new_return(26);
8382
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 3072 times.
12288 for(size_t j = 0; j < 3; ++j)
8383 {
8384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->fill[j], f))
8385 new_return(26);
8386
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->comb[j], f))
8387 new_return(26);
8388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->cset[j], f))
8389 new_return(26);
8390
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->price[j], f))
8391 new_return(26);
8392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (!p_iputw(bst->str[j], f))
8393 new_return(26);
8394 9216 }
8395 3072 }
8396
8397 //V_MISC >= 14
8398
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sfxMAX; ++q)
8399 {
8400
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.miscsfx[q],f))
8401 new_return(27);
8402 3072 }
8403
8404
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8405 {
8406 6 section_size=writesize;
8407 6 }
8408 12 }
8409
8410
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8411 {
8412 char ebuf[80];
8413 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8414 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8415 }
8416
8417 6 new_return(0);
8418 }
8419
8420 6 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8421 {
8422 //these are here to bypass compiler warnings about unused arguments
8423 6 Header=Header;
8424
8425 6 dword section_id=ID_ITEMS;
8426 6 dword section_version=V_ITEMS;
8427 6 dword section_cversion=CV_ITEMS;
8428 // dword section_size=0;
8429 6 dword section_size = 0;
8430
8431 //section id
8432
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8433 {
8434 new_return(1);
8435 }
8436
8437 //section version info
8438
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8439 {
8440 new_return(2);
8441 }
8442
8443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8444 {
8445 new_return(3);
8446 }
8447
8448
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8449 {
8450 12 fake_pack_writing=(writecycle==0);
8451
8452 //section size
8453
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8454 {
8455 new_return(4);
8456 }
8457
8458 12 writesize=0;
8459
8460 //finally... section data
8461
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXITEMS,f))
8462 {
8463 new_return(5);
8464 }
8465
8466
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8467 {
8468
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite(item_string[i], 64, f))
8469 {
8470 new_return(5);
8471 }
8472 3072 }
8473
8474
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8475 {
8476
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tile,f))
8477 {
8478 new_return(6);
8479 }
8480
8481
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].misc_flags,f))
8482 {
8483 new_return(7);
8484 }
8485
8486
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].csets,f))
8487 {
8488 new_return(8);
8489 }
8490
8491
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].frames,f))
8492 {
8493 new_return(9);
8494 }
8495
8496
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].speed,f))
8497 {
8498 new_return(10);
8499 }
8500
8501
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].delay,f))
8502 {
8503 new_return(11);
8504 }
8505
8506
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].ltm,f))
8507 {
8508 new_return(12);
8509 }
8510
8511
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].family,f))
8512 {
8513 new_return(13);
8514 }
8515
8516
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].fam_type,f))
8517 {
8518 new_return(14);
8519 }
8520
8521
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].power,f))
8522 {
8523 new_return(14);
8524 }
8525
8526
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].flags,f))
8527 {
8528 new_return(15);
8529 }
8530
8531
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].script,f))
8532 {
8533 new_return(16);
8534 }
8535
8536
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].count,f))
8537 {
8538 new_return(17);
8539 }
8540
8541
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].amount,f))
8542 {
8543 new_return(18);
8544 }
8545
8546
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].collect_script,f))
8547 {
8548 new_return(19);
8549 }
8550
8551
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].setmax,f))
8552 {
8553 new_return(21);
8554 }
8555
8556
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].max,f))
8557 {
8558 new_return(22);
8559 }
8560
8561
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].playsound,f))
8562 {
8563 new_return(23);
8564 }
8565
8566
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for(int32_t j=0; j<8; j++)
8567 {
8568
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].initiald[j],f))
8569 {
8570 new_return(24);
8571 }
8572 24576 }
8573
8574
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(int32_t j=0; j<2; j++)
8575 {
8576
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].initiala[j],f))
8577 {
8578 new_return(25);
8579 }
8580 6144 }
8581
8582
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn,f))
8583 {
8584 new_return(26);
8585 }
8586
8587
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn2,f))
8588 {
8589 new_return(27);
8590 }
8591
8592
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn3,f))
8593 {
8594 new_return(28);
8595 }
8596
8597
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn4,f))
8598 {
8599 new_return(29);
8600 }
8601
8602
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn5,f))
8603 {
8604 new_return(30);
8605 }
8606
8607
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn6,f))
8608 {
8609 new_return(31);
8610 }
8611
8612
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn7,f))
8613 {
8614 new_return(32);
8615 }
8616
8617
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn8,f))
8618 {
8619 new_return(33);
8620 }
8621
8622
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn9,f))
8623 {
8624 new_return(34);
8625 }
8626
8627
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn10,f))
8628 {
8629 new_return(35);
8630 }
8631
8632
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8633 {
8634 new_return(36);
8635 }
8636
8637
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc1,f))
8638 {
8639 new_return(37);
8640 }
8641
8642
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc2,f))
8643 {
8644 new_return(38);
8645 }
8646
8647
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8648 {
8649
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8650 {
8651 new_return(39);
8652 }
8653 6144 }
8654
8655
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc3,f))
8656 {
8657 new_return(40);
8658 }
8659
8660
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc4,f))
8661 {
8662 new_return(41);
8663 }
8664
8665
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc5,f))
8666 {
8667 new_return(42);
8668 }
8669
8670
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc6,f))
8671 {
8672 new_return(43);
8673 }
8674
8675
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc7,f))
8676 {
8677 new_return(44);
8678 }
8679
8680
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc8,f))
8681 {
8682 new_return(45);
8683 }
8684
8685
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc9,f))
8686 {
8687 new_return(46);
8688 }
8689
8690
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc10,f))
8691 {
8692 new_return(47);
8693 }
8694
8695
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound,f))
8696 {
8697 new_return(48);
8698 }
8699
8700
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound2,f))
8701 {
8702 new_return(48);
8703 }
8704
8705 //New itemdata vars -Z
8706 //! version 27
8707
8708
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].useweapon,f))
8709 {
8710 new_return(49);
8711 }
8712
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usedefence,f))
8713 {
8714 new_return(50);
8715 }
8716
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weaprange,f))
8717 {
8718 new_return(51);
8719 }
8720
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapduration,f))
8721 {
8722 new_return(52);
8723 }
8724
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 3072 times.
33792 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8725
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8726 {
8727 new_return(53);
8728 }
8729 30720 }
8730 //version 28
8731
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].duplicates,f))
8732 {
8733 new_return(54);
8734 }
8735
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < INITIAL_D; q++ )
8736 {
8737
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8738 {
8739 new_return(55);
8740 }
8741 24576 }
8742
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < INITIAL_A; q++ )
8743 {
8744
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].weap_initiala[q],f))
8745 {
8746 new_return(56);
8747 }
8748 6144 }
8749
8750
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].drawlayer,f))
8751 {
8752 new_return(57);
8753 }
8754
8755
8756
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxofs,f))
8757 {
8758 new_return(58);
8759 }
8760
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hyofs,f))
8761 {
8762 new_return(59);
8763 }
8764
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxsz,f))
8765 {
8766 new_return(60);
8767 }
8768
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hysz,f))
8769 {
8770 new_return(61);
8771 }
8772
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hzsz,f))
8773 {
8774 new_return(62);
8775 }
8776
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].xofs,f))
8777 {
8778 new_return(63);
8779 }
8780
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].yofs,f))
8781 {
8782 new_return(64);
8783 }
8784
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8785 {
8786 new_return(65);
8787 }
8788
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8789 {
8790 new_return(66);
8791 }
8792
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8793 {
8794 new_return(67);
8795 }
8796
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8797 {
8798 new_return(68);
8799 }
8800
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8801 {
8802 new_return(69);
8803 }
8804
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8805 {
8806 new_return(70);
8807 }
8808
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8809 {
8810 new_return(71);
8811 }
8812
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].weaponscript,f))
8813 {
8814 new_return(72);
8815 }
8816
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8817 {
8818 new_return(73);
8819 }
8820
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8821 {
8822
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8823 {
8824 new_return(74);
8825 }
8826 6144 }
8827
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8828 {
8829 new_return(75);
8830 }
8831
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tilew,f))
8832 {
8833 new_return(76);
8834 }
8835
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tileh,f))
8836 {
8837 new_return(77);
8838 }
8839
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8840 {
8841 new_return(78);
8842 }
8843
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8844 {
8845 new_return(79);
8846 }
8847
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8848 {
8849 new_return(80);
8850 }
8851
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].pickup,f))
8852 {
8853 new_return(81);
8854 }
8855
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pstring,f))
8856 {
8857 new_return(82);
8858 }
8859
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8860 {
8861 new_return(83);
8862 }
8863
8864
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8865 {
8866
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8867 {
8868 new_return(84);
8869 }
8870 6144 }
8871
8872 //InitD[] labels
8873
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < 8; q++ )
8874 {
8875
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8876 {
8877
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8878 {
8879 new_return(85);
8880 }
8881 1597440 }
8882
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8883 {
8884
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8885 {
8886 new_return(86);
8887 }
8888 1597440 }
8889
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8890 {
8891
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8892 {
8893 new_return(87);
8894 }
8895 1597440 }
8896
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8897 {
8898 new_return(88);
8899 }
8900 24576 }
8901
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8902 {
8903
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].sprite_initiala[q],f))
8904 {
8905 new_return(89);
8906 }
8907
8908 6144 }
8909
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].sprite_script,f))
8910 {
8911 new_return(90);
8912 }
8913
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickupflag,f))
8914 {
8915 new_return(91);
8916 }
8917
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 std::string dispname(itemsbuf[i].display_name);
8918
2/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3072 times.
✗ Branch 3 not taken.
3072 if(!p_putcstr(dispname,f))
8919 new_return(92);
8920
2/2
✓ Branch 0 taken 15360 times.
✓ Branch 1 taken 3072 times.
18432 for(int q = 0; q < BURNSPR_MAX; ++q)
8921 {
8922
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8923 new_return(93);
8924
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].light_rads[q], f))
8925 new_return(94);
8926 15360 }
8927 3072 }
8928
8929
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8930 {
8931 6 section_size=writesize;
8932 6 }
8933 12 }
8934
8935
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8936 {
8937 char ebuf[80];
8938 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8939 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8940 }
8941
8942 6 new_return(0);
8943 }
8944
8945 6 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8946 {
8947 //these are here to bypass compiler warnings about unused arguments
8948 6 Header=Header;
8949
8950 6 dword section_id=ID_WEAPONS;
8951 6 dword section_version=V_WEAPONS;
8952 6 dword section_cversion=CV_WEAPONS;
8953 6 dword section_size = 0;
8954
8955 //section id
8956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8957 {
8958 new_return(1);
8959 }
8960
8961 //section version info
8962
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8963 {
8964 new_return(2);
8965 }
8966
8967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8968 {
8969 new_return(3);
8970 }
8971
8972
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8973 {
8974 12 fake_pack_writing=(writecycle==0);
8975
8976 //section size
8977
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8978 {
8979 new_return(4);
8980 }
8981
8982 12 writesize=0;
8983
8984 //finally... section data
8985
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXWPNS,f))
8986 {
8987 new_return(5);
8988 }
8989
8990
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8991 {
8992
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite((char *)weapon_string[i], 64, f))
8993 {
8994 new_return(5);
8995 }
8996 3072 }
8997
8998
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8999 {
9000
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].misc,f))
9001 {
9002 new_return(7);
9003 }
9004
9005
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].csets,f))
9006 {
9007 new_return(8);
9008 }
9009
9010
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].frames,f))
9011 {
9012 new_return(9);
9013 }
9014
9015
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].speed,f))
9016 {
9017 new_return(10);
9018 }
9019
9020
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].type,f))
9021 {
9022 new_return(11);
9023 }
9024
9025
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(wpnsbuf[i].script,f))
9026 {
9027 new_return(12);
9028 }
9029
9030
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(wpnsbuf[i].tile,f))
9031 {
9032 new_return(12);
9033 }
9034 3072 }
9035
9036
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9037 {
9038 6 section_size=writesize;
9039 6 }
9040 12 }
9041
9042
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9043 {
9044 char ebuf[80];
9045 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9046 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9047 }
9048
9049 6 new_return(0);
9050 }
9051
9052 4080 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
9053 {
9054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9055 return qe_invalid;
9056
9057 4080 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9058 4080 bool is_0x80_screen = j >= 0x80;
9059
9060
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
4080 if(!p_putc(screen.valid,f))
9061 return qe_invalid;
9062
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 1998 times.
4080 if(!(screen.valid & mVALID))
9063 1998 return qe_OK;
9064 //Calculate what needs writing
9065 2082 uint32_t scr_has_flags = 0;
9066
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2080 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2082 if(screen.guytile || screen.guy || screen.roomflags || screen.str
9067
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
9068 2082 scr_has_flags |= SCRHAS_ROOMDATA;
9069
7/8
✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 282 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1680 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
2082 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
9070 290 scr_has_flags |= SCRHAS_ITEM;
9071
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
9072 18 scr_has_flags |= SCRHAS_TWARP;
9073
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 7754 times.
9650 else for(auto q = 0; q < 4; ++q)
9074 {
9075
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7586 times.
15340 if(screen.tilewarptype[q]
9076
2/2
✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 166 times.
7754 || screen.tilewarpdmap[q]
9077
2/2
✓ Branch 0 taken 7586 times.
✓ Branch 1 taken 2 times.
7588 || screen.tilewarpscr[q])
9078 {
9079 168 scr_has_flags |= SCRHAS_TWARP;
9080 168 break;
9081 }
9082 7586 }
9083
3/4
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
2082 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
9084
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 2 times.
2078 || screen.sidewarpoverlayflags)
9085 6 scr_has_flags |= SCRHAS_SWARP;
9086
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 3984 times.
4620 else for(auto q = 0; q < 4; ++q)
9087 {
9088
2/2
✓ Branch 0 taken 2544 times.
✓ Branch 1 taken 8 times.
6536 if(screen.sidewarptype[q] != wtSCROLL
9089
2/2
✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 1424 times.
3984 || screen.sidewarpdmap[q]
9090
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 8 times.
2560 || screen.sidewarpscr[q])
9091 {
9092 1440 scr_has_flags |= SCRHAS_SWARP;
9093 1440 break;
9094 }
9095 2544 }
9096
3/4
✓ Branch 0 taken 2038 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2038 times.
2082 if(screen.warparrivalx || screen.warparrivaly)
9097 44 scr_has_flags |= SCRHAS_WARPRET;
9098
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 6388 times.
7838 else for(auto q = 0; q < 4; ++q)
9099 {
9100
3/4
✓ Branch 0 taken 5800 times.
✓ Branch 1 taken 588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5800 times.
6388 if(screen.warpreturnx[q] || screen.warpreturny[q])
9101 {
9102 588 scr_has_flags |= SCRHAS_WARPRET;
9103 588 break;
9104 }
9105 5800 }
9106
9107
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2082 times.
2082 if(screen.hidelayers || screen.hidescriptlayers)
9108 scr_has_flags |= SCRHAS_LAYERS;
9109
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 11548 times.
13438 else for(auto q = 0; q < 6; ++q)
9110 {
9111
4/4
✓ Branch 0 taken 11366 times.
✓ Branch 1 taken 182 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11356 times.
11548 if(screen.layermap[q] || screen.layerscreen[q]
9112
1/2
✓ Branch 0 taken 11366 times.
✗ Branch 1 not taken.
11366 || screen.layeropacity[q]!=255)
9113 {
9114 192 scr_has_flags |= SCRHAS_LAYERS;
9115 192 break;
9116 }
9117 11356 }
9118
9119
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(screen.exitdir)
9120 4 scr_has_flags |= SCRHAS_MAZE;
9121
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 8312 times.
10390 else for(auto q = 0; q < 4; ++q)
9122 {
9123
1/2
✓ Branch 0 taken 8312 times.
✗ Branch 1 not taken.
8312 if(screen.path[q])
9124 {
9125 scr_has_flags |= SCRHAS_MAZE;
9126 break;
9127 }
9128 8312 }
9129
9130
4/4
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 752 times.
3072 if(screen.door_combo_set || screen.stairx
9131
3/4
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1820 times.
✗ Branch 3 not taken.
1848 || screen.stairy || screen.undercombo
9132
2/2
✓ Branch 0 taken 990 times.
✓ Branch 1 taken 830 times.
1820 || screen.undercset)
9133 1330 scr_has_flags |= SCRHAS_D_S_U;
9134
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 812 times.
832 else for(auto q = 0; q < 4; ++q)
9135 {
9136
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 732 times.
812 if(screen.door[q] != dNONE)
9137 {
9138 732 scr_has_flags |= SCRHAS_D_S_U;
9139 732 break;
9140 }
9141 80 }
9142
9143
2/2
✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 260 times.
3540 if(screen.flags || screen.flags2
9144
4/4
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1702 times.
✓ Branch 3 taken 34 times.
1822 || screen.flags3 || screen.flags4
9145
4/4
✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1674 times.
✓ Branch 3 taken 14 times.
1702 || screen.flags5 || screen.flags6
9146
4/4
✓ Branch 0 taken 1466 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1458 times.
✓ Branch 3 taken 8 times.
1674 || screen.flags7 || screen.flags8
9147
2/4
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1458 times.
✗ Branch 3 not taken.
1458 || screen.flags9 || screen.flags10
9148
1/2
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
1458 || screen.enemyflags)
9149 2082 scr_has_flags |= SCRHAS_FLAGS;
9150
9151
2/2
✓ Branch 0 taken 2032 times.
✓ Branch 1 taken 50 times.
2082 if(screen.pattern)
9152 50 scr_has_flags |= SCRHAS_ENEMY;
9153
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 14560 times.
15952 else for(auto q = 0; q < 10; ++q)
9154 {
9155
2/2
✓ Branch 0 taken 13920 times.
✓ Branch 1 taken 640 times.
14560 if(screen.enemy[q])
9156 {
9157 640 scr_has_flags |= SCRHAS_ENEMY;
9158 640 break;
9159 }
9160 13920 }
9161
9162
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
4158 if(screen.noreset || screen.nocarry
9163
3/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2076 times.
✓ Branch 3 taken 6 times.
2082 || screen.nextmap || screen.nextscr)
9164 6 scr_has_flags |= SCRHAS_CARRY;
9165
9166
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if(screen.script || screen.preloadscript)
9167 18 scr_has_flags |= SCRHAS_SCRIPT;
9168
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 16512 times.
18576 else for(auto q = 0; q < 8; ++q)
9169 {
9170
1/2
✓ Branch 0 taken 16512 times.
✗ Branch 1 not taken.
16512 if(screen.screeninitd[q])
9171 {
9172 scr_has_flags |= SCRHAS_SCRIPT;
9173 break;
9174 }
9175 16512 }
9176
9177
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 20820 times.
22902 for(auto q = 0; q < 10; ++q)
9178 {
9179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20820 times.
41640 if(screen.npcstrings[q]
9180
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_items[q]
9181
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_x[q]
9182
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_y[q])
9183 {
9184 scr_has_flags |= SCRHAS_UNUSED;
9185 break;
9186 }
9187 20820 }
9188
9189
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 99352 times.
100110 for(auto q = 0; q < 128; ++q)
9190 {
9191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98028 times.
197380 if(screen.secretcombo[q]
9192
2/2
✓ Branch 0 taken 98030 times.
✓ Branch 1 taken 1322 times.
99352 || screen.secretcset[q]
9193
2/2
✓ Branch 0 taken 98028 times.
✓ Branch 1 taken 2 times.
98030 || screen.secretflag[q])
9194 {
9195 1324 scr_has_flags |= SCRHAS_SECRETS;
9196 1324 break;
9197 }
9198 98028 }
9199
9200
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 40228 times.
40400 for(auto q = 0; q < 176; ++q)
9201 {
9202
4/4
✓ Branch 0 taken 38408 times.
✓ Branch 1 taken 1820 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 38318 times.
40228 if(screen.data[q] || screen.cset[q]
9203
2/2
✓ Branch 0 taken 38320 times.
✓ Branch 1 taken 88 times.
38408 || screen.sflag[q])
9204 {
9205 1910 scr_has_flags |= SCRHAS_COMBOFLAG;
9206 1910 break;
9207 }
9208 38318 }
9209
9210
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 1296 times.
2082 if(screen.color || screen.csensitive != 1
9211
3/4
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 752 times.
✓ Branch 3 taken 34 times.
786 || screen.oceansfx || screen.bosssfx
9212
2/4
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 752 times.
752 || screen.secretsfx || screen.holdupsfx
9213 || screen.timedwarptics || screen.screen_midi != -1
9214 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9215 2082 scr_has_flags |= SCRHAS_MISC;
9216
9217
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(scr_has_flags,f))
9218 return qe_invalid;
9219
9220 //Write stuff
9221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_ROOMDATA)
9222 {
9223
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guy,f))
9224 return qe_invalid;
9225
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(screen.guytile,f))
9226 return qe_invalid;
9227
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guycs,f))
9228 return qe_invalid;
9229
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.roomflags,f))
9230 return qe_invalid;
9231
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.str,f))
9232 return qe_invalid;
9233
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.room,f))
9234 return qe_invalid;
9235
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.catchall,f))
9236 return qe_invalid;
9237 2082 }
9238
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 290 times.
2082 if(scr_has_flags & SCRHAS_ITEM)
9239 {
9240
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.item,f))
9241 return qe_invalid;
9242
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.hasitem,f))
9243 return qe_invalid;
9244
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemx,f))
9245 return qe_invalid;
9246
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemy,f))
9247 return qe_invalid;
9248 290 }
9249
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 1500 times.
2082 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9250 {
9251
1/2
✓ Branch 0 taken 1500 times.
✗ Branch 1 not taken.
1500 if(!p_iputw(screen.warpreturnc,f))
9252 return qe_invalid;
9253 1500 }
9254
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 186 times.
2082 if(scr_has_flags & SCRHAS_TWARP)
9255 {
9256
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9257 {
9258
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarptype[k],f))
9259 return qe_invalid;
9260 744 }
9261
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9262 {
9263
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_iputw(screen.tilewarpdmap[k],f))
9264 return qe_invalid;
9265 744 }
9266
9267
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9268 {
9269
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarpscr[k],f))
9270 return qe_invalid;
9271 744 }
9272
9273
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if(!p_putc(screen.tilewarpoverlayflags,f))
9274 return qe_invalid;
9275 186 }
9276
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1446 times.
2082 if(scr_has_flags & SCRHAS_SWARP)
9277 {
9278
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9279 {
9280
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarptype[k],f))
9281 return qe_invalid;
9282 5784 }
9283
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9284 {
9285
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_iputw(screen.sidewarpdmap[k],f))
9286 return qe_invalid;
9287 5784 }
9288
9289
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9290 {
9291
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarpscr[k],f))
9292 return qe_invalid;
9293 5784 }
9294
9295
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpoverlayflags,f))
9296 return qe_invalid;
9297
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpindex,f))
9298 return qe_invalid;
9299 1446 }
9300
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 632 times.
2082 if(scr_has_flags & SCRHAS_WARPRET)
9301 {
9302
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9303 {
9304
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturnx[k],f))
9305 return qe_invalid;
9306 2528 }
9307
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9308 {
9309
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturny[k],f))
9310 return qe_invalid;
9311 2528 }
9312
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivalx,f))
9313 return qe_invalid;
9314
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivaly,f))
9315 return qe_invalid;
9316 632 }
9317
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 192 times.
2082 if(scr_has_flags & SCRHAS_LAYERS)
9318 {
9319
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9320 {
9321
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layermap[k],f))
9322 return qe_invalid;
9323 1152 }
9324
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9325 {
9326
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layerscreen[k],f))
9327 return qe_invalid;
9328 1152 }
9329
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9330 {
9331
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layeropacity[k],f))
9332 return qe_invalid;
9333 1152 }
9334
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidelayers,f))
9335 return qe_invalid;
9336
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidescriptlayers,f))
9337 return qe_invalid;
9338 192 }
9339
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(scr_has_flags & SCRHAS_MAZE)
9340 {
9341
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t k=0; k<4; k++)
9342 {
9343
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_putc(screen.path[k],f))
9344 return qe_invalid;
9345 16 }
9346
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_putc(screen.exitdir,f))
9347 return qe_invalid;
9348 4 }
9349
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2062 times.
2082 if(scr_has_flags & SCRHAS_D_S_U)
9350 {
9351
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.door_combo_set,f))
9352 return qe_invalid;
9353
2/2
✓ Branch 0 taken 8248 times.
✓ Branch 1 taken 2062 times.
10310 for(int32_t k=0; k<4; k++)
9354 {
9355
1/2
✓ Branch 0 taken 8248 times.
✗ Branch 1 not taken.
8248 if(!p_putc(screen.door[k],f))
9356 return qe_invalid;
9357 8248 }
9358
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairx,f))
9359 return qe_invalid;
9360
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairy,f))
9361 return qe_invalid;
9362
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.undercombo,f))
9363 return qe_invalid;
9364
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.undercset,f))
9365 return qe_invalid;
9366 2062 }
9367
2/2
✓ Branch 0 taken 1336 times.
✓ Branch 1 taken 746 times.
2082 if(scr_has_flags & SCRHAS_FLAGS)
9368 {
9369
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags,f))
9370 return qe_invalid;
9371
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags2,f))
9372 return qe_invalid;
9373
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags3,f))
9374 return qe_invalid;
9375
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags4,f))
9376 return qe_invalid;
9377
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags5,f))
9378 return qe_invalid;
9379
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags6,f))
9380 return qe_invalid;
9381
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags7,f))
9382 return qe_invalid;
9383
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags8,f))
9384 return qe_invalid;
9385
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags9,f))
9386 return qe_invalid;
9387
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags10,f))
9388 return qe_invalid;
9389
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.enemyflags,f))
9390 return qe_invalid;
9391 746 }
9392
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 690 times.
2082 if(scr_has_flags & SCRHAS_ENEMY)
9393 {
9394
2/2
✓ Branch 0 taken 6900 times.
✓ Branch 1 taken 690 times.
7590 for(int32_t k=0; k<10; k++)
9395 {
9396
1/2
✓ Branch 0 taken 6900 times.
✗ Branch 1 not taken.
6900 if(!p_iputw(screen.enemy[k],f))
9397 return qe_invalid;
9398 6900 }
9399
1/2
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
690 if(!p_putc(screen.pattern,f))
9400 return qe_invalid;
9401 690 }
9402
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 6 times.
2082 if(scr_has_flags & SCRHAS_CARRY)
9403 {
9404
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.noreset,f))
9405 return qe_invalid;
9406
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.nocarry,f))
9407 return qe_invalid;
9408
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextmap,f))
9409 return qe_invalid;
9410
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextscr,f))
9411 return qe_invalid;
9412 6 }
9413
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
2082 if(scr_has_flags & SCRHAS_SCRIPT)
9414 {
9415
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(screen.script,f))
9416 return qe_invalid;
9417
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(screen.preloadscript,f))
9418 return qe_invalid;
9419
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for ( int32_t q = 0; q < 8; q++ )
9420 {
9421
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_iputl(screen.screeninitd[q],f))
9422 return qe_invalid;
9423 144 }
9424 18 }
9425
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(scr_has_flags & SCRHAS_UNUSED)
9426 {
9427 for ( int32_t q = 0; q < 10; q++ )
9428 {
9429 if(!p_iputl(screen.npcstrings[q],f))
9430 return qe_invalid;
9431 }
9432 for ( int32_t q = 0; q < 10; q++ )
9433 {
9434 if(!p_iputw(screen.new_items[q],f))
9435 return qe_invalid;
9436 }
9437 for ( int32_t q = 0; q < 10; q++ )
9438 {
9439 if(!p_iputw(screen.new_item_x[q],f))
9440 return qe_invalid;
9441 }
9442 for ( int32_t q = 0; q < 10; q++ )
9443 {
9444 if(!p_iputw(screen.new_item_y[q],f))
9445 return qe_invalid;
9446 }
9447 }
9448
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 1324 times.
2082 if(scr_has_flags & SCRHAS_SECRETS)
9449 {
9450
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9451 {
9452
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_iputw(screen.secretcombo[k],f))
9453 return qe_invalid;
9454 169472 }
9455
9456
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9457 {
9458
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretcset[k],f))
9459 return qe_invalid;
9460 169472 }
9461
9462
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9463 {
9464
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretflag[k],f))
9465 return qe_invalid;
9466 169472 }
9467 1324 }
9468
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 1910 times.
2082 if(scr_has_flags & SCRHAS_COMBOFLAG)
9469 {
9470
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9471 {
9472
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_iputw(screen.data[k],f))
9473 return qe_invalid;
9474 336160 }
9475
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9476 {
9477
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.sflag[k],f))
9478 return qe_invalid;
9479 336160 }
9480
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9481 {
9482
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.cset[k],f))
9483 return qe_invalid;
9484 336160 }
9485 1910 }
9486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_MISC)
9487 {
9488
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.color,f))
9489 return qe_invalid;
9490
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.csensitive,f))
9491 return qe_invalid;
9492
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.oceansfx,f))
9493 return qe_invalid;
9494
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.bosssfx,f))
9495 return qe_invalid;
9496
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.secretsfx,f))
9497 return qe_invalid;
9498
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.holdupsfx,f))
9499 return qe_invalid;
9500
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.timedwarptics,f))
9501 return qe_invalid;
9502
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.screen_midi,f))
9503 return qe_invalid;
9504
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_layer,f))
9505 return qe_invalid;
9506
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_show,f))
9507 return qe_invalid;
9508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(!p_putc(screen.lens_hide,f))
9509 return qe_invalid;
9510 2082 }
9511
9512 2082 dword numffc = screen.numFFC();
9513
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(numffc,f))
9514 return qe_invalid;
9515
2/2
✓ Branch 0 taken 45816 times.
✓ Branch 1 taken 2082 times.
47898 for(int32_t k=0; k<numffc; ++k)
9516 {
9517 45816 ffcdata const& tempffc = screen.ffcs[k];
9518
9519
1/2
✓ Branch 0 taken 45816 times.
✗ Branch 1 not taken.
45816 if(!p_iputw(tempffc.data,f))
9520 return qe_invalid;
9521
9522
2/2
✓ Branch 0 taken 44726 times.
✓ Branch 1 taken 1090 times.
45816 if(!tempffc.data) //don't save the rest of the ffc
9523 44726 continue;
9524
9525
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.cset,f))
9526 return qe_invalid;
9527
9528
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.delay,f))
9529 return qe_invalid;
9530
9531
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.x,f))
9532 return qe_invalid;
9533
9534
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.y,f))
9535 return qe_invalid;
9536
9537
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vx,f))
9538 return qe_invalid;
9539
9540
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vy,f))
9541 return qe_invalid;
9542
9543
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ax,f))
9544 return qe_invalid;
9545
9546
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ay,f))
9547 return qe_invalid;
9548
9549
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.link,f))
9550 return qe_invalid;
9551
9552
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_width,f))
9553 return qe_invalid;
9554
9555
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_height,f))
9556 return qe_invalid;
9557
9558
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.txsz,f))
9559 return qe_invalid;
9560
9561
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.tysz,f))
9562 return qe_invalid;
9563
9564
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.flags,f))
9565 return qe_invalid;
9566
9567
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.script,f))
9568 return qe_invalid;
9569
9570
2/2
✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 1090 times.
9810 for(auto q = 0; q < 8; ++q)
9571 {
9572
1/2
✓ Branch 0 taken 8720 times.
✗ Branch 1 not taken.
8720 if(!p_iputl(tempffc.initd[q],f))
9573 return qe_invalid;
9574 8720 }
9575
9576
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[0]/10000,f))
9577 return qe_invalid;
9578
9579
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[1]/10000,f))
9580 return qe_invalid;
9581 1090 }
9582
9583
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putlstr(screen.usr_notes, f))
9584 return qe_invalid;
9585
9586 2082 return qe_OK;
9587 4080 }
9588
9589 6 int32_t writemaps(PACKFILE *f, zquestheader *)
9590 {
9591 6 dword section_id=ID_MAPS;
9592 6 dword section_version=V_MAPS;
9593 6 dword section_cversion=CV_MAPS;
9594 6 dword section_size = 0;
9595
9596 //section id
9597
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9598 {
9599 new_return(1);
9600 }
9601
9602 //section version info
9603
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9604 {
9605 new_return(2);
9606 }
9607
9608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9609 {
9610 new_return(3);
9611 }
9612
9613
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9614 {
9615 12 fake_pack_writing=(writecycle==0);
9616
9617 //section size
9618
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9619 {
9620 new_return(4);
9621 }
9622
9623 12 writesize=0;
9624
9625
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(map_count,f))
9626 {
9627 new_return(5);
9628 }
9629 12 map_autolayers.resize(map_count*6);
9630
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
42 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9631 {
9632 30 byte valid = 0;
9633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 for(int32_t j=0; j<MAPSCRS; j++)
9634 {
9635
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9636 break;
9637 240 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9638
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 210 times.
240 if(screen.valid & mVALID)
9639 {
9640 30 valid = 1;
9641 30 break;
9642 }
9643 210 }
9644
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_putc(valid,f))
9645 {
9646 new_return(6);
9647 }
9648
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!valid) continue;
9649
9650 { //per-map info
9651
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for(int q = 0; q < 6; ++q)
9652 {
9653 180 size_t ind = i*6+q;
9654
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(!p_iputw(map_autolayers[ind],f))
9655 new_return(7);
9656 180 }
9657 }
9658
9659
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 30 times.
4110 for(int32_t j=0; j<MAPSCRS; j++)
9660 4080 writemapscreen(f,i,j);
9661 30 }
9662
9663
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9664 {
9665 6 section_size=writesize;
9666 6 }
9667 12 }
9668
9669
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9670 {
9671 char ebuf[80];
9672 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9673 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9674 }
9675
9676 6 new_return(0);
9677 }
9678
9679 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9680 {
9681 //Check what needs writing
9682 byte combo_has_flags = 0;
9683 383638 for(auto q = 0; q < 8; ++q)
9684 {
9685 767276 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9686 383638 || (q < 4 && tmp_cmb.attributes[q]))
9687 {
9688 combo_has_flags |= CHAS_ATTRIB;
9689 break;
9690 }
9691 383638 }
9692
3/4
✓ Branch 0 taken 96864 times.
✓ Branch 1 taken 96864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96836 times.
96836 if (tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9693
3/4
✓ Branch 0 taken 96862 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96862 times.
✗ Branch 3 not taken.
96864 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9694
3/4
✓ Branch 0 taken 96860 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96862 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9695
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9696
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9697
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9698
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9699
3/4
✓ Branch 0 taken 96836 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigchange || tmp_cmb.trigprox
9700
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9701
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9702
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9703
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9704
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.exdoor_dir > -1
9705
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9706
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9707
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9708
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trigdmlevel > -1
9709
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9710
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9711
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9712
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9713
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_pushtime != 8 || tmp_cmb.trig_shieldjinxtime > -2
9714
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9715
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9716 96892 combo_has_flags |= CHAS_TRIG;
9717
2/2
✓ Branch 0 taken 290508 times.
✓ Branch 1 taken 96836 times.
387344 else for(int q = 0; q < 3; ++q)
9718
1/2
✓ Branch 0 taken 290508 times.
✗ Branch 1 not taken.
290508 if(tmp_cmb.trigtint[q])
9719 combo_has_flags |= CHAS_TRIG;
9720
4/4
✓ Branch 0 taken 96840 times.
✓ Branch 1 taken 96888 times.
✓ Branch 2 taken 96704 times.
✓ Branch 3 taken 136 times.
193728 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9721 193592 combo_has_flags |= CHAS_FLAG;
9722
6/6
✓ Branch 0 taken 93610 times.
✓ Branch 1 taken 93290 times.
✓ Branch 2 taken 80124 times.
✓ Branch 3 taken 13486 times.
✓ Branch 4 taken 89494 times.
✓ Branch 5 taken 9434 times.
80380 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9723
6/6
✓ Branch 0 taken 80100 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 80070 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 80060 times.
✓ Branch 5 taken 10 times.
80124 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9724
1/2
✓ Branch 0 taken 80060 times.
✗ Branch 1 not taken.
80060 || tmp_cmb.animflags)
9725 196334 combo_has_flags |= CHAS_ANIM;
9726
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 70224 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97004 times.
26780 if(tmp_cmb.script || tmp_cmb.label.size())
9727 70224 combo_has_flags |= CHAS_SCRIPT;
9728
2/2
✓ Branch 0 taken 776032 times.
✓ Branch 1 taken 97004 times.
873036 else for(auto q = 0; q < 8; ++q)
9729 {
9730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776032 times.
776032 if(tmp_cmb.initd[q])
9731 {
9732 combo_has_flags |= CHAS_SCRIPT;
9733 break;
9734 }
9735 776032 }
9736
6/6
✓ Branch 0 taken 52696 times.
✓ Branch 1 taken 114532 times.
✓ Branch 2 taken 52184 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 70224 times.
✓ Branch 5 taken 18040 times.
219412 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9737
2/4
✓ Branch 0 taken 52184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52184 times.
✗ Branch 3 not taken.
52184 || tmp_cmb.type || tmp_cmb.csets)
9738 185268 combo_has_flags |= CHAS_BASIC;
9739
3/4
✓ Branch 0 taken 96996 times.
✓ Branch 1 taken 34136 times.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
159856 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9740
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9741
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9742
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9743
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9744
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9745
1/2
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
96996 || tmp_cmb.lift_parent_item)
9746 131132 combo_has_flags |= CHAS_LIFT;
9747
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
✓ Branch 2 taken 97004 times.
✗ Branch 3 not taken.
228128 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9748
7/10
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97000 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96996 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
97004 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9749
5/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap)
9750 131132 combo_has_flags |= CHAS_GENERAL;
9751
9752
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
131132 if(!p_putc(combo_has_flags,f))
9753 {
9754 34128 return 50;
9755 }
9756
2/2
✓ Branch 0 taken 44820 times.
✓ Branch 1 taken 52184 times.
97004 if(!combo_has_flags) return 0; //Valid, done reading
9757 //Write the combo
9758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44820 times.
44820 if(combo_has_flags&CHAS_BASIC)
9759 {
9760
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_iputl(tmp_cmb.o_tile,f))
9761 return 6;
9762
9763
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flip,f))
9764 return 7;
9765
9766
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.walk,f))
9767 return 8;
9768
9769
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.type,f))
9770 return 9;
9771
9772
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flag,f))
9773 return 15;
9774
9775
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.csets,f))
9776 return 10;
9777 44820 }
9778
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(combo_has_flags&CHAS_SCRIPT)
9779 {
9780 p_putcstr(tmp_cmb.label, f);
9781
9782 if(!p_iputw(tmp_cmb.script,f))
9783 return 26;
9784 for ( int32_t q = 0; q < 8; q++ )
9785 if(!p_iputl(tmp_cmb.initd[q],f))
9786 return 27;
9787 }
9788
2/2
✓ Branch 0 taken 27474 times.
✓ Branch 1 taken 17346 times.
44820 if(combo_has_flags&CHAS_ANIM)
9789 {
9790
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.frames,f))
9791 return 11;
9792
9793
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.speed,f))
9794 return 12;
9795
9796
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_iputw(tmp_cmb.nextcombo,f))
9797 return 13;
9798
9799
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.nextcset,f))
9800 return 14;
9801
9802
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanim,f))
9803 return 16;
9804
9805
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanimy,f))
9806 return 18;
9807
9808
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.animflags,f))
9809 return 19;
9810 17346 }
9811
2/2
✓ Branch 0 taken 42552 times.
✓ Branch 1 taken 2268 times.
44820 if(combo_has_flags&CHAS_ATTRIB)
9812 {
9813
2/2
✓ Branch 0 taken 9072 times.
✓ Branch 1 taken 2268 times.
11340 for ( int32_t q = 0; q < 4; q++ )
9814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9072 times.
9072 if(!p_iputl(tmp_cmb.attributes[q],f))
9815 return 20;
9816
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ )
9817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_putc(tmp_cmb.attribytes[q],f))
9818 return 25;
9819
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9821 return 32;
9822 2268 }
9823
2/2
✓ Branch 0 taken 44636 times.
✓ Branch 1 taken 184 times.
44820 if(combo_has_flags&CHAS_FLAG)
9824 {
9825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
184 if(!p_iputl(tmp_cmb.usrflags,f))
9826 return 21;
9827
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if(!p_iputw(tmp_cmb.genflags,f))
9828 return 33;
9829 184 }
9830
2/2
✓ Branch 0 taken 44652 times.
✓ Branch 1 taken 168 times.
44820 if(combo_has_flags&CHAS_TRIG)
9831 {
9832
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for ( int32_t q = 0; q < 6; q++ )
9833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9834 return 22;
9835
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.triggerlevel,f))
9836 return 23;
9837
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggerbtn,f))
9838 return 34;
9839
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggeritem,f))
9840 return 35;
9841
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigtimer,f))
9842 return 36;
9843
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigsfx,f))
9844 return 37;
9845
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigchange,f))
9846 return 38;
9847
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if(!p_iputw(tmp_cmb.trigprox,f))
9848 return 39;
9849
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigctr,f))
9850 return 40;
9851
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigctramnt,f))
9852 return 41;
9853
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triglbeam,f))
9854 return 42;
9855
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcschange,f))
9856 return 43;
9857
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnitem,f))
9858 return 44;
9859
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnenemy,f))
9860 return 45;
9861
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exstate,f))
9862 return 46;
9863
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.spawnip,f))
9864 return 47;
9865
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcopycat,f))
9866 return 48;
9867
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcooldown,f))
9868 return 49;
9869
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_cid,f))
9870 return 50;
9871
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.prompt_cs,f))
9872 return 51;
9873
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_x,f))
9874 return 52;
9875
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_y,f))
9876 return 53;
9877
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_lstate,f))
9878 return 69;
9879
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_gstate,f))
9880 return 70;
9881
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trig_statetime,f))
9882 return 71;
9883
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_genscr,f))
9884 return 72;
9885
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_group,f))
9886 return 76;
9887
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_group_val,f))
9888 return 77;
9889
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_dir,f))
9890 return 89;
9891
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_ind,f))
9892 return 90;
9893
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_levelitems,f))
9894 return 91;
9895
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9896 return 92;
9897
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
672 for(int q = 0; q < 3; ++q)
9898
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
504 if(!p_iputw(tmp_cmb.trigtint[q],f))
9899 return 93;
9900
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9901 return 94;
9902
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9903 return 95;
9904
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigquaketime,f))
9905 return 96;
9906
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigwavytime,f))
9907 return 97;
9908
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9909 return 98;
9910
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9911 return 99;
9912
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9913 return 100;
9914
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9915 return 101;
9916
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_pushtime,f))
9917 return 102;
9918
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if (!p_iputw(tmp_cmb.trig_shieldjinxtime, f))
9919 return 103;
9920 168 }
9921
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_LIFT)
9922 {
9923
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftcmb,f))
9924 return 54;
9925
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftcs,f))
9926 return 55;
9927
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftundercmb,f))
9928 return 56;
9929
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftundercs,f))
9930 return 57;
9931
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftdmg,f))
9932 return 58;
9933
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftlvl,f))
9934 return 59;
9935
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftitm,f))
9936 return 60;
9937
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftflags,f))
9938 return 61;
9939
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftgfx,f))
9940 return 62;
9941
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsprite,f))
9942 return 63;
9943
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsfx,f))
9944 return 64;
9945
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9946 return 65;
9947
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9948 return 66;
9949
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifthei,f))
9950 return 67;
9951
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifttime,f))
9952 return 68;
9953
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lift_parent_item,f))
9954 return 78;
9955 8 }
9956
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_GENERAL)
9957 {
9958
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_mult,f))
9959 return 73;
9960
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_div,f))
9961 return 74;
9962
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputzf(tmp_cmb.speed_add,f))
9963 return 75;
9964
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_appear,f))
9965 return 79;
9966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(!p_putc(tmp_cmb.sfx_disappear,f))
9967 return 80;
9968
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_loop,f))
9969 return 81;
9970
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_walking,f))
9971 return 82;
9972
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_standing,f))
9973 return 83;
9974
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_appear,f))
9975 return 84;
9976
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_disappear,f))
9977 return 85;
9978
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_walking,f))
9979 return 86;
9980
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_standing,f))
9981 return 87;
9982
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_tap,f))
9983 return 88;
9984 8 }
9985 44820 return 0;
9986 131132 }
9987
9988 6 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9989 {
9990 //these are here to bypass compiler warnings about unused arguments
9991 6 version=version;
9992 6 build=build;
9993
9994 word combos_used;
9995 6 dword section_id=ID_COMBOS;
9996 6 dword section_version=V_COMBOS;
9997 6 dword section_cversion=CV_COMBOS;
9998 // dword section_size=0;
9999 6 combos_used = count_combos()-start_combo;
10000
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, max_combos);
10001
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, MAXCOMBOS);
10002 6 dword section_size = 0;
10003
10004 //section id
10005
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10006 {
10007 new_return(1);
10008 }
10009
10010 //section version info
10011
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10012 {
10013 new_return(2);
10014 }
10015
10016
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
10017 {
10018 new_return(3);
10019 }
10020
10021
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10022 {
10023 12 fake_pack_writing=(writecycle==0);
10024
10025 //section size
10026
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10027 {
10028 new_return(4);
10029 }
10030
10031 12 writesize=0;
10032
10033 //finally... section data
10034 12 combos_used=count_combos()-start_combo;
10035
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, max_combos);
10036
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, MAXCOMBOS);
10037
10038
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(combos_used,f))
10039 {
10040 new_return(5);
10041 }
10042
10043 12 size_t end_combo = start_combo+combos_used;
10044
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 12 times.
97016 for(size_t q = start_combo; q < end_combo; ++q)
10045 {
10046 97004 auto ret = writecombo_loop(f, section_version, combobuf[q]);
10047
1/4
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
97004 if(ret) new_return(ret);
10048 97004 }
10049
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10050 {
10051 6 section_size=writesize;
10052 6 }
10053 12 }
10054
10055
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10056 {
10057 char ebuf[80];
10058 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10059 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10060 }
10061
10062 6 new_return(0);
10063 6 }
10064
10065 6 int32_t writecomboaliases(PACKFILE *f, word version, word build)
10066 {
10067 //these are here to bypass compiler warnings about unused arguments
10068 6 version=version;
10069 6 build=build;
10070
10071 6 dword section_id=ID_COMBOALIASES;
10072 6 dword section_version=V_COMBOALIASES;
10073 6 dword section_cversion=CV_COMBOALIASES;
10074 6 dword section_size=0;
10075
10076 //section id
10077
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10078 {
10079 new_return(1);
10080 }
10081
10082 //section version info
10083
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10084 {
10085 new_return(2);
10086 }
10087
10088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10089 {
10090 new_return(3);
10091 }
10092
10093
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10094 {
10095 12 fake_pack_writing=(writecycle==0);
10096
10097 //section size
10098
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10099 {
10100 new_return(4);
10101 }
10102
10103 12 writesize=0;
10104
10105 //finally... section data
10106
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 12 times.
98316 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10107 {
10108
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_iputw(combo_aliases[j].combo,f))
10109 {
10110 new_return(5);
10111 }
10112
10113
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].cset,f))
10114 {
10115 new_return(6);
10116 }
10117
10118 98304 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10119
10120
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].width,f))
10121 {
10122 new_return(7);
10123 }
10124
10125
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].height,f))
10126 {
10127 new_return(8);
10128 }
10129
10130
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].layermask,f))
10131 {
10132 new_return(9);
10133 }
10134
10135
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10136 {
10137
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_iputw(combo_aliases[j].combos[k],f))
10138 {
10139 new_return(10);
10140 }
10141 99792 }
10142
10143
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10144 {
10145
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_putc(combo_aliases[j].csets[k],f))
10146 {
10147 new_return(11);
10148 }
10149 99792 }
10150 98304 }
10151
10152 //Combo pools!
10153 int16_t num_cpools;
10154
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 98300 times.
98310 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10155 {
10156
2/2
✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 2 times.
98300 if(combo_pools[num_cpools].valid()) //found a used pool
10157 {
10158 2 ++num_cpools;
10159 2 break;
10160 }
10161 98298 }
10162
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if(num_cpools < 0) num_cpools = 0;
10163
10164
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_cpools,f))
10165 {
10166 new_return(12);
10167 }
10168
10169
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(auto cp = 0; cp < num_cpools; ++cp)
10170 {
10171 6 combo_pool const& pool = combo_pools[cp];
10172 6 int32_t num_combos = pool.combos.size();
10173
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10174 {
10175 new_return(13);
10176 }
10177
10178
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10179 {
10180 26 cpool_entry const& entry = pool.combos.at(q);
10181
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10182 {
10183 new_return(14);
10184 }
10185
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10186 {
10187 new_return(15);
10188 }
10189
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10190 {
10191 new_return(16);
10192 }
10193 26 }
10194 6 }
10195
10196 //Autocombos!
10197 int16_t num_cautos;
10198
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 98304 times.
98316 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10199 {
10200
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if (combo_autos[num_cautos].valid()) //found a used autocombo
10201 {
10202 ++num_cautos;
10203 break;
10204 }
10205 98304 }
10206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (num_cautos < 0) num_cautos = 0;
10207
10208
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputw(num_cautos, f))
10209 {
10210 new_return(17);
10211 }
10212
10213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for (auto ca = 0; ca < num_cautos; ++ca)
10214 {
10215 combo_auto const& cauto = combo_autos[ca];
10216 if (!p_putc(cauto.getType(), f))
10217 {
10218 new_return(18);
10219 }
10220 if (!p_iputl(cauto.getIconDisplay(), f))
10221 {
10222 new_return(19);
10223 }
10224 if (!p_iputl(cauto.getEraseCombo(), f))
10225 {
10226 new_return(20);
10227 }
10228 if (!p_putc(cauto.getFlags(), f))
10229 {
10230 new_return(21);
10231 }
10232 if (!p_putc(cauto.getArg(), f))
10233 {
10234 new_return(22);
10235 }
10236 int32_t num_combos = cauto.combos.size();
10237 if (!p_iputl(num_combos, f))
10238 {
10239 new_return(23);
10240 }
10241
10242 for (auto q = 0; q < num_combos; ++q)
10243 {
10244 autocombo_entry const& entry = cauto.combos.at(q);
10245 if (!p_putc(entry.ctype, f))
10246 {
10247 new_return(24);
10248 }
10249 if (!p_iputl(entry.cid, f))
10250 {
10251 new_return(25);
10252 }
10253 }
10254 }
10255
10256
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10257 {
10258 6 section_size=writesize;
10259 6 }
10260 12 }
10261
10262
10263
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10264 {
10265 char ebuf[80];
10266 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10267 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10268 }
10269
10270 6 new_return(0);
10271 }
10272
10273 6 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10274 {
10275 //these are here to bypass compiler warnings about unused arguments
10276 6 version=version;
10277 6 build=build;
10278 6 start_cset=start_cset;
10279 6 max_csets=max_csets;
10280
10281 6 dword section_id=ID_CSETS;
10282 6 dword section_version=V_CSETS;
10283 6 dword section_cversion=CV_CSETS;
10284 6 int32_t palcycles = count_palcycles(&QMisc);
10285 // int32_t palcyccount = count_palcycles(&QMisc);
10286 6 dword section_size = 0;
10287
10288 //section id
10289
10290
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10291 {
10292 new_return(1);
10293 }
10294
10295 //section version info
10296
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10297 {
10298 new_return(2);
10299 }
10300
10301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10302 {
10303 new_return(3);
10304 }
10305
10306
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10307 {
10308 12 fake_pack_writing=(writecycle==0);
10309
10310 //section size
10311
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10312 {
10313 new_return(4);
10314 }
10315
10316 12 writesize=0;
10317
10318 //finally... section data
10319
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(colordata,psTOTAL255,f))
10320 {
10321 new_return(5);
10322 }
10323
10324
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10325 {
10326 new_return(6);
10327 }
10328
10329
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(palcycles,f))
10330 {
10331 new_return(15);
10332 }
10333
10334
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 12 times.
288 for(int32_t i=0; i<palcycles; i++)
10335 {
10336
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10337 {
10338
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].first,f))
10339 {
10340 new_return(16);
10341 }
10342 828 }
10343
10344
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10345 {
10346
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].count,f))
10347 {
10348 new_return(17);
10349 }
10350 828 }
10351
10352
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10353 {
10354
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].speed,f))
10355 {
10356 new_return(18);
10357 }
10358 828 }
10359 276 }
10360
10361
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10362 {
10363 6 section_size=writesize;
10364 6 }
10365 12 }
10366
10367
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10368 {
10369 char ebuf[80];
10370 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10371 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10372 }
10373
10374 6 new_return(0);
10375 }
10376
10377 6 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10378 {
10379 //these are here to bypass compiler warnings about unused arguments
10380 6 version=version;
10381 6 build=build;
10382 6 start_msgstr=start_msgstr;
10383 6 max_msgstrs=max_msgstrs;
10384
10385 6 dword section_id=ID_STRINGS;
10386 6 dword section_version=V_STRINGS;
10387 6 dword section_cversion=CV_STRINGS;
10388 6 dword section_size = 0;
10389
10390 //section id
10391
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10392 {
10393 new_return(1);
10394 }
10395
10396 //section version info
10397
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10398 {
10399 new_return(2);
10400 }
10401
10402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10403 {
10404 new_return(3);
10405 }
10406
10407
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10408 {
10409 12 fake_pack_writing=(writecycle==0);
10410
10411 //section size
10412
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10413 {
10414 new_return(4);
10415 }
10416
10417 12 writesize=0;
10418
10419 //finally... section data
10420
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(msg_count,f))
10421 {
10422 return qe_invalid;
10423 }
10424
10425
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 12 times.
314 for(int32_t i=0; i<msg_count; i++)
10426 {
10427 302 int32_t sz = MsgStrings[i].s.size();
10428
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(sz > 8192) sz = 8192;
10429
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(sz, f))
10430 {
10431 return qe_invalid;
10432 }
10433
10434 302 char const* tmpstr = MsgStrings[i].s.c_str();
10435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (sz > 0)
10436 {
10437
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (!pfwrite((void*)tmpstr,sz, f))
10438 {
10439 return qe_invalid;
10440 }
10441 302 }
10442
10443
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].nextstring,f))
10444 {
10445 return qe_invalid;
10446 }
10447
10448
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].tile,f))
10449 {
10450 return qe_invalid;
10451 }
10452
10453
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].cset,f))
10454 {
10455 return qe_invalid;
10456 }
10457
10458
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].trans?1:0,f))
10459 {
10460 return qe_invalid;
10461 }
10462
10463
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].font,f))
10464 {
10465 return qe_invalid;
10466 }
10467
10468
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].x,f))
10469 {
10470 return qe_invalid;
10471 }
10472
10473
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].y,f))
10474 {
10475 return qe_invalid;
10476 }
10477
10478
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].w,f))
10479 {
10480 return qe_invalid;
10481 }
10482
10483
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].h,f))
10484 {
10485 return qe_invalid;
10486 }
10487
10488
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].hspace,f))
10489 {
10490 return qe_invalid;
10491 }
10492
10493
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].vspace,f))
10494 {
10495 return qe_invalid;
10496 }
10497
10498
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].stringflags,f))
10499 {
10500 return qe_invalid;
10501 }
10502
10503
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 302 times.
1510 for(int32_t q = 0; q < 4; ++q)
10504 {
10505
1/2
✓ Branch 0 taken 1208 times.
✗ Branch 1 not taken.
1208 if(!p_putc(MsgStrings[i].margins[q],f))
10506 {
10507 return qe_invalid;
10508 }
10509 1208 }
10510
10511
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10512 {
10513 return qe_invalid;
10514 }
10515
10516
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_cset,f))
10517 {
10518 return qe_invalid;
10519 }
10520
10521
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_x,f))
10522 {
10523 return qe_invalid;
10524 }
10525
10526
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_y,f))
10527 {
10528 return qe_invalid;
10529 }
10530
10531
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_tw,f))
10532 {
10533 return qe_invalid;
10534 }
10535
10536
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_th,f))
10537 {
10538 return qe_invalid;
10539 }
10540
10541
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_type,f))
10542 {
10543 return qe_invalid;
10544 }
10545
10546
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_color,f))
10547 {
10548 return qe_invalid;
10549 }
10550
10551
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].drawlayer,f))
10552 {
10553 return qe_invalid;
10554 }
10555
10556
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].sfx,f))
10557 {
10558 return qe_invalid;
10559 }
10560
10561
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].listpos,f))
10562 {
10563 return qe_invalid;
10564 }
10565 302 }
10566
10567
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10568 {
10569 6 section_size=writesize;
10570 6 }
10571 12 }
10572
10573
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10574 {
10575 char ebuf[80];
10576 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10577 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10578 }
10579
10580 6 new_return(0);
10581 6 }
10582
10583 int32_t writestrings_text(PACKFILE *f)
10584 {
10585 std::map<int32_t, int32_t> msglistcache;
10586
10587 for(int32_t index = 1; index<msg_count; index++)
10588 {
10589 for(int32_t i=1; i<msg_count; i++)
10590 {
10591 if(MsgStrings[i].listpos==index)
10592 {
10593 msglistcache[index-1]=i;
10594 break;
10595 }
10596 }
10597 }
10598
10599 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10600 {
10601 fake_pack_writing=(writecycle==0);
10602 char ebuf[32];
10603
10604 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10605
10606 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10607 {
10608 return qe_invalid;
10609 }
10610
10611 for(int32_t i=1; i<msg_count; i++)
10612 {
10613 int32_t str = msglistcache[i-1];
10614
10615 if(!str)
10616 continue;
10617
10618 if(MsgStrings[str].nextstring != 0)
10619 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10620 else
10621 sprintf(ebuf,"\n\n___%d___\n", str);
10622
10623 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10624 {
10625 return qe_invalid;
10626 }
10627
10628 encode_msg_str(str);
10629
10630 if(!pfwrite(&msgbuf,(int32_t)strlen(msgbuf),f))
10631 {
10632 return qe_invalid;
10633 }
10634 }
10635 }
10636
10637 new_return(0);
10638 }
10639
10640 1 int32_t writestrings_tsv(PACKFILE *f)
10641 {
10642 1 std::stringstream ss;
10643
10644 int32_t str;
10645
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10646
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){
10647 35 encode_msg_str(str);
10648 35 return msgbuf;
10649 }},
10650
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10651
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10652
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10653
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10654
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10655
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10656
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10657
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10658
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10659
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10660
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10661
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10662
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10663
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10664
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10665
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10666
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10667
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10668
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10669
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10670
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10671
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10672
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10673
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10674 };
10675
10676
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10677 {
10678
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10679
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10680 1 break;
10681
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10682 }
10683
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10684
10685 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10686
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10687
10688
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10689 {
10690 35 str = i;
10691 35 auto& msg = MsgStrings[str];
10692
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10693 {
10694
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10695
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10696
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10697 35 break;
10698
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10699
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10700
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10701 35 }
10702
10703
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10704
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10705 {
10706 return qe_invalid;
10707 }
10708
10709 1 new_return(0);
10710 1 }
10711
10712 std::string parse_msg_str(std::string const& s);
10713
10714 void parse_strings_tsv(std::string tsv)
10715 {
10716 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10717 { "message", [](auto& msg, auto& text){ msg.s = parse_msg_str(text); } },
10718 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10719 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10720 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10721 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10722 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10723 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10724 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10725 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10726 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10727 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10728 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10729 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10730 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10731 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10732 { "margin", [&](auto& msg, auto& text){
10733 std::vector<std::string> strs;
10734 util::split(text, strs, ' ');
10735 if (strs.size() != 4)
10736 throw std::runtime_error("margin field must have 4 components");
10737 msg.margins[0] = std::stoi(strs[0]);
10738 msg.margins[1] = std::stoi(strs[1]);
10739 msg.margins[2] = std::stoi(strs[2]);
10740 msg.margins[3] = std::stoi(strs[3]);
10741 } },
10742 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10743 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10744 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10745 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10746 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10747 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10748 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10749 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10750 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10751 };
10752
10753 std::vector<std::string> rows;
10754 util::split(tsv, rows, '\n');
10755 if (rows.size())
10756 {
10757 std::string last = rows.back();
10758 util::trimstr(last);
10759 if (last.empty())
10760 rows.pop_back();
10761 }
10762 if (rows.size() <= 1)
10763 throw std::runtime_error("missing header row");
10764
10765 std::vector<std::string> columns;
10766 util::split(rows[0], columns, '\t');
10767 for (auto name : columns)
10768 {
10769 if (!fields.contains(name))
10770 throw std::runtime_error(fmt::format("invalid field: {}", name));
10771 }
10772
10773 int start_index = 1;
10774 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10775 start_index += 1;
10776
10777 int num_strings = rows.size() - start_index + 1;
10778 if (num_strings > MAXMSGS-1)
10779 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10780
10781 std::vector<MsgStr> msgs;
10782 msgs.reserve(num_strings);
10783 for (int i = start_index; i < rows.size(); i++)
10784 {
10785 std::vector<std::string> strs;
10786 util::split(rows[i], strs, '\t');
10787 if (strs.size() != columns.size())
10788 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10789
10790 int j = 0;
10791 auto& msg = msgs.emplace_back();
10792 for (auto& name : columns)
10793 {
10794 auto& fn = fields[name];
10795 try
10796 {
10797 fn(msg, strs[j++]);
10798 }
10799 catch (std::exception& ex)
10800 {
10801 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10802 }
10803 }
10804 }
10805
10806 init_msgstrings(0, msgs.size());
10807 for (int i = 0; i < msgs.size(); i++)
10808 MsgStrings[i + 1] = msgs[i];
10809 msg_count = msgs.size();
10810 msglistcache.clear();
10811 }
10812
10813 bool isblanktile(tiledata *buf, int32_t i);
10814 6 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10815 {
10816 //these are here to bypass compiler warnings about unused arguments
10817 6 version=version;
10818 6 build=build;
10819
10820 int32_t tiles_used;
10821 6 dword section_id=ID_TILES;
10822 6 dword section_version=V_TILES;
10823 6 dword section_cversion=CV_TILES;
10824 6 al_trace("Counting tiles used\n");
10825 6 tiles_used = count_tiles(newtilebuf)-start_tile;
10826
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, max_tiles);
10827
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10828 6 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10829 6 dword section_size = 0;
10830
10831 //section id
10832
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10833 {
10834 new_return(1);
10835 }
10836
10837 //section version info
10838
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10839 {
10840 new_return(2);
10841 }
10842
10843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10844 {
10845 new_return(3);
10846 }
10847
10848
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10849 {
10850 12 fake_pack_writing=(writecycle==0);
10851
10852 //section size
10853
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10854 {
10855 new_return(4);
10856 }
10857
10858 12 writesize=0;
10859
10860 //finally... section data
10861 12 tiles_used=count_tiles(newtilebuf)-start_tile;
10862
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, max_tiles);
10863
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10864
10865
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(tiles_used,f))
10866 {
10867 new_return(5);
10868 }
10869
10870
2/2
✓ Branch 0 taken 448054 times.
✓ Branch 1 taken 12 times.
448066 for(int32_t i=0; i<tiles_used; ++i)
10871 {
10872
2/2
✓ Branch 0 taken 238750 times.
✓ Branch 1 taken 209304 times.
448054 if(isblanktile(newtilebuf, start_tile+i))
10873 {
10874
1/2
✓ Branch 0 taken 238750 times.
✗ Branch 1 not taken.
238750 if(!p_putc(0,f))
10875 new_return(8);
10876 238750 }
10877 else
10878 {
10879 209304 int format = newtilebuf[start_tile+i].format;
10880
1/2
✓ Branch 0 taken 209304 times.
✗ Branch 1 not taken.
209304 if(!p_putc(format,f))
10881 {
10882 new_return(6);
10883 }
10884
10885
2/2
✓ Branch 0 taken 207706 times.
✓ Branch 1 taken 1598 times.
209304 if (format == tf4Bit)
10886 {
10887 byte temp_tile[128];
10888 207706 byte *di = temp_tile;
10889 207706 byte *src = newtilebuf[start_tile+i].data;
10890
2/2
✓ Branch 0 taken 26586368 times.
✓ Branch 1 taken 207706 times.
26794074 for (int32_t si=0; si<256; si+=2)
10891 {
10892 26586368 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10893 26586368 ++di;
10894 26586368 }
10895
1/2
✓ Branch 0 taken 207706 times.
✗ Branch 1 not taken.
207706 if (!pfwrite(temp_tile,128,f))
10896 {
10897 new_return(7);
10898 }
10899 207706 }
10900
1/2
✓ Branch 0 taken 1598 times.
✗ Branch 1 not taken.
1598 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10901 {
10902 new_return(7);
10903 }
10904 }
10905 448054 }
10906
10907
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10908 {
10909 6 section_size=writesize;
10910 6 }
10911 12 }
10912
10913
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10914 {
10915 char ebuf[80];
10916 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10917 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10918 }
10919
10920 6 new_return(0);
10921 }
10922
10923 /* MIDI Format
10924 section_id LONG
10925 section_version WORD
10926 section_cversion WORD
10927 section_size LONG
10928 midi_flags 32 Byte ? BITFIELD[252]
10929
10930 [
10931 title 36
10932 start 4
10933 loop_start 4
10934 loop_end 4
10935 loop 2
10936 volume 2
10937 midi *
10938 ]
10939
10940 */
10941
10942 6 int32_t writemidis(PACKFILE *f)
10943 {
10944 6 dword section_id=ID_MIDIS;
10945 6 dword section_version=V_MIDIS;
10946 6 dword section_cversion=CV_MIDIS;
10947 6 dword section_size = 0;
10948
10949 //section id
10950
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10951 {
10952 new_return(1);
10953 }
10954
10955 //section version info
10956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10957 {
10958 new_return(2);
10959 }
10960
10961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10962 {
10963 new_return(3);
10964 }
10965
10966
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10967 {
10968 12 fake_pack_writing=(writecycle==0);
10969
10970 //section size
10971
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10972 {
10973 new_return(4);
10974 }
10975
10976 12 writesize=0;
10977
10978 //finally... section data
10979
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10980 {
10981 new_return(5);
10982 }
10983
10984
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10985 {
10986
2/2
✓ Branch 0 taken 2964 times.
✓ Branch 1 taken 60 times.
3024 if(get_bit(midi_flags,i))
10987 {
10988
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10989 {
10990 new_return(6);
10991 }
10992
10993
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].start,f))
10994 {
10995 new_return(7);
10996 }
10997
10998
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_start,f))
10999 {
11000 new_return(8);
11001 }
11002
11003
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_end,f))
11004 {
11005 new_return(9);
11006 }
11007
11008
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].loop,f))
11009 {
11010 new_return(10);
11011 }
11012
11013
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].volume,f))
11014 {
11015 new_return(11);
11016 }
11017
11018
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
11019 {
11020 new_return(12);
11021 }
11022
11023
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].format, sizeof(customtunes[i].format),f))
11024 {
11025 new_return(13);
11026 }
11027
11028
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 switch(customtunes[i].format)
11029 {
11030 case MFORMAT_MIDI:
11031
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!write_midi((MIDI*) customtunes[i].data,f)) new_return(14);
11032
11033 60 break;
11034
11035 default:
11036 new_return(15);
11037 break;
11038 }
11039 60 }
11040 3024 }
11041
11042
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11043 {
11044 6 section_size=writesize;
11045 6 }
11046 12 }
11047
11048
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11049 {
11050 char ebuf[80];
11051 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11052 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11053 }
11054
11055 6 new_return(0);
11056 }
11057
11058 6 int32_t writecheats(PACKFILE *f, zquestheader *Header)
11059 {
11060 6 dword section_id=ID_CHEATS;
11061 6 dword section_version=V_CHEATS;
11062 6 dword section_cversion=CV_CHEATS;
11063 6 dword section_size = 0;
11064
11065 //section id
11066
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11067 {
11068 new_return(1);
11069 }
11070
11071 //section version info
11072
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11073 {
11074 new_return(2);
11075 }
11076
11077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11078 {
11079 new_return(3);
11080 }
11081
11082
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11083 {
11084 12 fake_pack_writing=(writecycle==0);
11085
11086 //section size
11087
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11088 {
11089 new_return(4);
11090 }
11091
11092 12 writesize=0;
11093
11094 //finally... section data
11095
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
11096 {
11097 new_return(5);
11098 }
11099
11100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(Header->data_flags[ZQ_CHEATS2])
11101 {
11102
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zcheats.flags,f))
11103 {
11104 new_return(6);
11105 }
11106
11107
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
11108 {
11109 new_return(7);
11110 }
11111 12 }
11112
11113
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11114 {
11115 6 section_size=writesize;
11116 6 }
11117 12 }
11118
11119
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11120 {
11121 char ebuf[80];
11122 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11123 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11124 }
11125
11126 6 new_return(0);
11127 }
11128
11129 6 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11130 {
11131 //these are here to bypass compiler warnings about unused arguments
11132 6 Header=Header;
11133
11134 6 dword section_id=ID_GUYS;
11135 6 dword section_version=V_GUYS;
11136 6 dword section_cversion=CV_GUYS;
11137 6 dword section_size=0;
11138
11139 //section id
11140
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11141 {
11142 new_return(1);
11143 }
11144
11145 //section version info
11146
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11147 {
11148 new_return(2);
11149 }
11150
11151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11152 {
11153 new_return(3);
11154 }
11155
11156
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11157 {
11158 12 fake_pack_writing=(writecycle==0);
11159
11160 //section size
11161
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11162 {
11163 new_return(4);
11164 }
11165
11166 12 writesize=0;
11167
11168 //finally... section data
11169
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11170 {
11171
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite((char *)guy_string[i], 64, f))
11172 {
11173 new_return(5);
11174 }
11175 6144 }
11176
11177
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6144 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11178 {
11179
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].flags,f))
11180 {
11181 new_return(6);
11182 }
11183
11184
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].flags2,f))
11185 {
11186 new_return(7);
11187 }
11188
11189
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tile,f))
11190 {
11191 new_return(8);
11192 }
11193
11194
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].width,f))
11195 {
11196 new_return(9);
11197 }
11198
11199
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].height,f))
11200 {
11201 new_return(10);
11202 }
11203
11204
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].s_tile,f))
11205 {
11206 new_return(11);
11207 }
11208
11209
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_width,f))
11210 {
11211 new_return(12);
11212 }
11213
11214
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_height,f))
11215 {
11216 new_return(13);
11217 }
11218
11219
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].e_tile,f))
11220 {
11221 new_return(14);
11222 }
11223
11224
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_width,f))
11225 {
11226 new_return(15);
11227 }
11228
11229
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_height,f))
11230 {
11231 new_return(16);
11232 }
11233
11234
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hp,f))
11235 {
11236 new_return(17);
11237 }
11238
11239
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].family,f))
11240 {
11241 new_return(18);
11242 }
11243
11244
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].cset,f))
11245 {
11246 new_return(19);
11247 }
11248
11249
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].anim,f))
11250 {
11251 new_return(20);
11252 }
11253
11254
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_anim,f))
11255 {
11256 new_return(21);
11257 }
11258
11259
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].frate,f))
11260 {
11261 new_return(22);
11262 }
11263
11264
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_frate,f))
11265 {
11266 new_return(23);
11267 }
11268
11269
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].dp,f))
11270 {
11271 new_return(24);
11272 }
11273
11274
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].wdp,f))
11275 {
11276 new_return(25);
11277 }
11278
11279
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weapon,f))
11280 {
11281 new_return(26);
11282 }
11283
11284
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].rate,f))
11285 {
11286 new_return(27);
11287 }
11288
11289
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hrate,f))
11290 {
11291 new_return(28);
11292 }
11293
11294
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].step,f))
11295 {
11296 new_return(29);
11297 }
11298
11299
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].homing,f))
11300 {
11301 new_return(30);
11302 }
11303
11304
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].grumble,f))
11305 {
11306 new_return(31);
11307 }
11308
11309
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].item_set,f))
11310 {
11311 new_return(32);
11312 }
11313
11314
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[0], f))
11315 {
11316 new_return(33);
11317 }
11318
11319
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[1],f))
11320 {
11321 new_return(34);
11322 }
11323
11324
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[2],f))
11325 {
11326 new_return(35);
11327 }
11328
11329
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[3],f))
11330 {
11331 new_return(36);
11332 }
11333
11334
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[4],f))
11335 {
11336 new_return(37);
11337 }
11338
11339
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[5],f))
11340 {
11341 new_return(38);
11342 }
11343
11344
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[6],f))
11345 {
11346 new_return(39);
11347 }
11348
11349
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[7],f))
11350 {
11351 new_return(40);
11352 }
11353
11354
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[8],f))
11355 {
11356 new_return(41);
11357 }
11358
11359
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[9],f))
11360 {
11361 new_return(42);
11362 }
11363
11364
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bgsfx,f))
11365 {
11366 new_return(43);
11367 }
11368
11369
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bosspal,f))
11370 {
11371 new_return(44);
11372 }
11373
11374
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].extend,f))
11375 {
11376 new_return(45);
11377 }
11378
11379
2/2
✓ Branch 0 taken 116736 times.
✓ Branch 1 taken 6144 times.
122880 for(int32_t j=0; j < edefLAST; j++)
11380 {
11381
1/2
✓ Branch 0 taken 116736 times.
✗ Branch 1 not taken.
116736 if(!p_putc(guysbuf[i].defense[j],f))
11382 {
11383 new_return(46);
11384 }
11385 116736 }
11386
11387
4/6
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4096 times.
✓ Branch 3 taken 2048 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
6144 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11388 {
11389 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11390 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11391 //Force SFX_HIT here.
11392
11393 }
11394
11395
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].hitsfx,f))
11396 {
11397 new_return(47);
11398 }
11399
11400
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].deadsfx,f))
11401 {
11402 new_return(48);
11403 }
11404
11405
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[10],f))
11406 {
11407 new_return(49);
11408 }
11409
11410
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[11],f))
11411 {
11412 new_return(50);
11413 }
11414
11415 //New 2.6 defences
11416
2/2
✓ Branch 0 taken 135168 times.
✓ Branch 1 taken 6144 times.
141312 for(int32_t j=edefLAST; j < edefLAST255; j++)
11417 {
11418
1/2
✓ Branch 0 taken 135168 times.
✗ Branch 1 not taken.
135168 if(!p_putc(guysbuf[i].defense[j],f))
11419 {
11420 new_return(51);
11421 }
11422 135168 }
11423
11424 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11425
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].txsz,f))
11426 {
11427 new_return(52);
11428 }
11429
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tysz,f))
11430 {
11431 new_return(53);
11432 }
11433
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxsz,f))
11434 {
11435 new_return(54);
11436 }
11437
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hysz,f))
11438 {
11439 new_return(55);
11440 }
11441
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hzsz,f))
11442 {
11443 new_return(56);
11444 }
11445 // These are not fixed types, but ints, so they are safe to use here.
11446
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxofs,f))
11447 {
11448 new_return(57);
11449 }
11450
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hyofs,f))
11451 {
11452 new_return(58);
11453 }
11454
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].xofs,f))
11455 {
11456 new_return(59);
11457 }
11458
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].yofs,f))
11459 {
11460 new_return(60);
11461 }
11462
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].zofs,f))
11463 {
11464 new_return(61);
11465 }
11466
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].wpnsprite,f))
11467 {
11468 new_return(62);
11469 }
11470
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].SIZEflags,f))
11471 {
11472 new_return(63);
11473 }
11474
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozentile,f))
11475 {
11476 new_return(64);
11477 }
11478
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozencset,f))
11479 {
11480 new_return(65);
11481 }
11482
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozenclock,f))
11483 {
11484 new_return(66);
11485 }
11486
11487
2/2
✓ Branch 0 taken 61440 times.
✓ Branch 1 taken 6144 times.
67584 for ( int32_t q = 0; q < 10; q++ )
11488 {
11489
1/2
✓ Branch 0 taken 61440 times.
✗ Branch 1 not taken.
61440 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11490 {
11491 new_return(67);
11492 }
11493 61440 }
11494
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].firesfx,f))
11495 {
11496 new_return(68);
11497 }
11498 //misc 16->31
11499
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[15],f))
11500 {
11501 new_return(69);
11502 }
11503
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[16],f))
11504 {
11505 new_return(70);
11506 }
11507
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[17],f))
11508 {
11509 new_return(71);
11510 }
11511
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[18],f))
11512 {
11513 new_return(72);
11514 }
11515
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[19],f))
11516 {
11517 new_return(73);
11518 }
11519
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[20],f))
11520 {
11521 new_return(74);
11522 }
11523
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[21],f))
11524 {
11525 new_return(75);
11526 }
11527
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[22],f))
11528 {
11529 new_return(76);
11530 }
11531
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[23],f))
11532 {
11533 new_return(77);
11534 }
11535
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[24],f))
11536 {
11537 new_return(78);
11538 }
11539
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[25],f))
11540 {
11541 new_return(79);
11542 }
11543
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[26],f))
11544 {
11545 new_return(80);
11546 }
11547
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[27],f))
11548 {
11549 new_return(81);
11550 }
11551
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[28],f))
11552 {
11553 new_return(82);
11554 }
11555
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[29],f))
11556 {
11557 new_return(83);
11558 }
11559
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[30],f))
11560 {
11561 new_return(84);
11562 }
11563
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[31],f))
11564 {
11565 new_return(85);
11566 }
11567
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11568 {
11569
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].movement[q],f))
11570 {
11571 new_return(86);
11572 }
11573 196608 }
11574
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11575 {
11576
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11577 {
11578 new_return(87);
11579 }
11580 196608 }
11581
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].script,f))
11582 {
11583 new_return(88);
11584 }
11585
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11586 {
11587
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].initD[q],f))
11588 {
11589 new_return(89);
11590 }
11591 49152 }
11592
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 6144 times.
18432 for ( int32_t q = 0; q < 2; q++ )
11593 {
11594
1/2
✓ Branch 0 taken 12288 times.
✗ Branch 1 not taken.
12288 if(!p_iputl(guysbuf[i].initA[q],f))
11595 {
11596 new_return(90);
11597 }
11598 12288 }
11599
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].editorflags,f))
11600 {
11601 new_return(91);
11602 }
11603 //somehow forgot these in the older builds -Z
11604
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[12],f))
11605 {
11606 new_return(92);
11607 }
11608
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[13],f))
11609 {
11610 new_return(93);
11611 }
11612
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[14],f))
11613 {
11614 new_return(94);
11615 }
11616
11617 //Enemy Editor InitD[] labels
11618
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11619 {
11620
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11621 {
11622
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11623 {
11624 new_return(95);
11625 }
11626 3194880 }
11627
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11628 {
11629
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11630 {
11631 new_return(96);
11632 }
11633 3194880 }
11634 49152 }
11635
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weaponscript,f))
11636 {
11637 new_return(97);
11638 }
11639 //eweapon initD
11640
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11641 {
11642
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11643 {
11644 new_return(98);
11645 }
11646 49152 }
11647
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].moveflags,f))
11648 new_return(99);
11649
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_shadow,f))
11650 new_return(100);
11651
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_death,f))
11652 new_return(101);
11653
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_spawn,f))
11654 new_return(102);
11655 6144 }
11656
11657
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11658 {
11659 6 section_size=writesize;
11660 6 }
11661 12 }
11662
11663
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11664 {
11665 char ebuf[80];
11666 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11667 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11668 }
11669
11670 6 new_return(0);
11671 }
11672
11673 6 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11674 {
11675 //these are here to bypass compiler warnings about unused arguments
11676 6 Header=Header;
11677
11678 6 dword section_id=ID_HEROSPRITES;
11679 6 dword section_version=V_HEROSPRITES;
11680 6 dword section_cversion=CV_HEROSPRITES;
11681 6 dword section_size=0;
11682
11683 //section id
11684
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11685 {
11686 new_return(1);
11687 }
11688
11689 //section version info
11690
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11691 {
11692 new_return(2);
11693 }
11694
11695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11696 {
11697 new_return(3);
11698 }
11699
11700
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11701 {
11702 12 fake_pack_writing=(writecycle==0);
11703
11704 //section size
11705
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11706 {
11707 new_return(4);
11708 }
11709
11710 12 writesize=0;
11711
11712 //finally... section data
11713
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11714 {
11715
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(walkspr[i][spr_tile],f))
11716 {
11717 new_return(5);
11718 }
11719
11720
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_flip],f))
11721 {
11722 new_return(5);
11723 }
11724
11725
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_extend],f))
11726 {
11727 new_return(5);
11728 }
11729 48 }
11730
11731
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11732 {
11733
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stabspr[i][spr_tile],f))
11734 {
11735 new_return(6);
11736 }
11737
11738
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_flip],f))
11739 {
11740 new_return(6);
11741 }
11742
11743
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_extend],f))
11744 {
11745 new_return(6);
11746 }
11747 48 }
11748
11749
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11750 {
11751
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashspr[i][spr_tile],f))
11752 {
11753 new_return(7);
11754 }
11755
11756
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_flip],f))
11757 {
11758 new_return(7);
11759 }
11760
11761
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_extend],f))
11762 {
11763 new_return(7);
11764 }
11765 48 }
11766
11767
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11768 {
11769
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(floatspr[i][spr_tile],f))
11770 {
11771 new_return(8);
11772 }
11773
11774
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_flip],f))
11775 {
11776 new_return(8);
11777 }
11778
11779
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_extend],f))
11780 {
11781 new_return(8);
11782 }
11783 48 }
11784
11785
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11786 {
11787
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(swimspr[i][spr_tile],f))
11788 {
11789 new_return(8);
11790 }
11791
11792
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_flip],f))
11793 {
11794 new_return(8);
11795 }
11796
11797
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_extend],f))
11798 {
11799 new_return(8);
11800 }
11801 48 }
11802
11803
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11804 {
11805
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(divespr[i][spr_tile],f))
11806 {
11807 new_return(9);
11808 }
11809
11810
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_flip],f))
11811 {
11812 new_return(9);
11813 }
11814
11815
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_extend],f))
11816 {
11817 new_return(9);
11818 }
11819 48 }
11820
11821
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11822 {
11823
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(poundspr[i][spr_tile],f))
11824 {
11825 new_return(10);
11826 }
11827
11828
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_flip],f))
11829 {
11830 new_return(10);
11831 }
11832
11833
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_extend],f))
11834 {
11835 new_return(10);
11836 }
11837 48 }
11838
11839
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(castingspr[spr_tile],f))
11840 {
11841 new_return(11);
11842 }
11843
11844
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_flip],f))
11845 {
11846 new_return(11);
11847 }
11848
11849
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_extend],f))
11850 {
11851 new_return(11);
11852 }
11853
11854
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for(int32_t i=0; i<2; i++)
11855 {
11856
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for(int32_t j=0; j<spr_holdmax; j++)
11857 {
11858
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(holdspr[i][j][spr_tile],f))
11859 {
11860 new_return(12);
11861 }
11862
11863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11864 {
11865 new_return(12);
11866 }
11867
11868
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11869 {
11870 new_return(12);
11871 }
11872 72 }
11873 24 }
11874
11875
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11876 {
11877
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(jumpspr[i][spr_tile],f))
11878 {
11879 new_return(13);
11880 }
11881
11882
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11883 {
11884 new_return(13);
11885 }
11886
11887
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11888 {
11889 new_return(13);
11890 }
11891 48 }
11892
11893
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11894 {
11895
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(chargespr[i][spr_tile],f))
11896 {
11897 new_return(13);
11898 }
11899
11900
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_flip],f))
11901 {
11902 new_return(13);
11903 }
11904
11905
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_extend],f))
11906 {
11907 new_return(13);
11908 }
11909 48 }
11910
11911
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)zinit.hero_swim_speed,f))
11912 {
11913 new_return(14);
11914 }
11915
11916 //{ V_HEROSPRITES >= 7
11917
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11918 {
11919
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozenspr[q][spr_tile],f))
11920 new_return(15);
11921
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11922 new_return(15);
11923
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11924 new_return(15);
11925 48 }
11926
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11927 {
11928
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11929 new_return(15);
11930
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11931 new_return(15);
11932
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11933 new_return(15);
11934 48 }
11935
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11936 {
11937
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfirespr[q][spr_tile],f))
11938 new_return(15);
11939
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11940 new_return(15);
11941
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11942 new_return(15);
11943 48 }
11944
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11945 {
11946
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11947 new_return(15);
11948
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11949 new_return(15);
11950
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11951 new_return(15);
11952 48 }
11953
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11954 {
11955
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(diggingspr[q][spr_tile],f))
11956 new_return(15);
11957
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11958 new_return(15);
11959
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11960 new_return(15);
11961 48 }
11962
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11963 {
11964
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingrodspr[q][spr_tile],f))
11965 new_return(15);
11966
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11967 new_return(15);
11968
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11969 new_return(15);
11970 48 }
11971
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11972 {
11973
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingcanespr[q][spr_tile],f))
11974 new_return(15);
11975
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11976 new_return(15);
11977
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11978 new_return(15);
11979 48 }
11980
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11981 {
11982
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pushingspr[q][spr_tile],f))
11983 new_return(15);
11984
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11985 new_return(15);
11986
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11987 new_return(15);
11988 48 }
11989
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11990 {
11991
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingspr[q][spr_tile],f))
11992 new_return(15);
11993
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11994 new_return(15);
11995
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11996 new_return(15);
11997
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11998 new_return(15);
11999 48 }
12000
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12001 {
12002
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
12003 new_return(15);
12004
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
12005 new_return(15);
12006
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
12007 new_return(15);
12008 48 }
12009
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12010 {
12011
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunnedspr[q][spr_tile],f))
12012 new_return(15);
12013
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
12014 new_return(15);
12015
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
12016 new_return(15);
12017 48 }
12018
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12019 {
12020
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
12021 new_return(15);
12022
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
12023 new_return(15);
12024
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
12025 new_return(15);
12026 48 }
12027
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12028 {
12029
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowningspr[q][spr_tile],f))
12030 new_return(15);
12031
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_flip],f))
12032 new_return(15);
12033
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_extend],f))
12034 new_return(15);
12035 48 }
12036
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12037 {
12038
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
12039 new_return(15);
12040
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
12041 new_return(15);
12042
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
12043 new_return(15);
12044 48 }
12045
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12046 {
12047
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(fallingspr[q][spr_tile],f))
12048 new_return(15);
12049
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_flip],f))
12050 new_return(15);
12051
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_extend],f))
12052 new_return(15);
12053 48 }
12054
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12055 {
12056
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shockedspr[q][spr_tile],f))
12057 new_return(15);
12058
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_flip],f))
12059 new_return(15);
12060
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_extend],f))
12061 new_return(15);
12062 48 }
12063
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12064 {
12065
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
12066 new_return(15);
12067
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
12068 new_return(15);
12069
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
12070 new_return(15);
12071 48 }
12072
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12073 {
12074
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pullswordspr[q][spr_tile],f))
12075 new_return(15);
12076
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
12077 new_return(15);
12078
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
12079 new_return(15);
12080 48 }
12081
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12082 {
12083
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(readingspr[q][spr_tile],f))
12084 new_return(15);
12085
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_flip],f))
12086 new_return(15);
12087
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_extend],f))
12088 new_return(15);
12089 48 }
12090
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12091 {
12092
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slash180spr[q][spr_tile],f))
12093 new_return(15);
12094
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_flip],f))
12095 new_return(15);
12096
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_extend],f))
12097 new_return(15);
12098 48 }
12099
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12100 {
12101
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashZ4spr[q][spr_tile],f))
12102 new_return(15);
12103
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
12104 new_return(15);
12105
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
12106 new_return(15);
12107 48 }
12108
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12109 {
12110
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(dashspr[q][spr_tile],f))
12111 new_return(15);
12112
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_flip],f))
12113 new_return(15);
12114
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_extend],f))
12115 new_return(15);
12116 48 }
12117
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12118 {
12119
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(bonkspr[q][spr_tile],f))
12120 new_return(15);
12121
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12122 new_return(15);
12123
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12124 new_return(15);
12125 48 }
12126
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12127 {
12128
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(medallionsprs[q][spr_tile],f))
12129 new_return(15);
12130
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12131 new_return(15);
12132
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12133 new_return(15);
12134 36 }
12135
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12136 {
12137
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimspr[q][spr_tile],f))
12138 new_return(16);
12139
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12140 new_return(16);
12141
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12142 new_return(16);
12143 48 }
12144
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12145 {
12146
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12147 new_return(17);
12148
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12149 new_return(17);
12150
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12151 new_return(17);
12152 48 }
12153
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12154 {
12155
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12156 new_return(17);
12157
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12158 new_return(17);
12159
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12160 new_return(17);
12161 48 }
12162
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12163 {
12164
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12165 new_return(17);
12166
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12167 new_return(17);
12168
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12169 new_return(17);
12170 48 }
12171
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12172 {
12173
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12174 new_return(18);
12175
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12176 new_return(18);
12177
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12178 new_return(18);
12179 48 }
12180
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12181 {
12182
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(hammeroffsets[q],f))
12183 new_return(19);
12184 48 }
12185
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q)
12186 {
12187
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12188 new_return(20);
12189
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12190 new_return(20);
12191
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12192 new_return(20);
12193 36 }
12194
12195
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12196 {
12197 new_return(21);
12198 }
12199
12200
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12201 {
12202 new_return(21);
12203 }
12204
12205
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12206 {
12207 new_return(21);
12208 }
12209
12210
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12211 {
12212
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12213 new_return(22);
12214
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12215 new_return(22);
12216
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12217 new_return(22);
12218 48 }
12219
12220
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
12221 {
12222
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(revslashspr[i][spr_tile],f))
12223 {
12224 new_return(23);
12225 }
12226
12227
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12228 {
12229 new_return(23);
12230 }
12231
12232
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12233 {
12234 new_return(23);
12235 }
12236 48 }
12237
12238
12239
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 12 times.
1764 for (int32_t q = 0; q < wMax; q++) // Player defense values
12240 {
12241
1/2
✓ Branch 0 taken 1752 times.
✗ Branch 1 not taken.
1752 if (!p_putc(hero_defence[q], f))
12242 new_return(15);
12243 1752 }
12244 //}
12245
12246
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12247 {
12248 6 section_size=writesize;
12249 6 }
12250 12 }
12251
12252 //More data will come here
12253
12254
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12255 {
12256 char ebuf[80];
12257 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12258 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12259 }
12260
12261 6 new_return(0);
12262 }
12263
12264 6 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12265 {
12266 6 dword section_id=ID_SUBSCREEN;
12267 6 dword section_version=V_SUBSCREEN;
12268 6 dword section_cversion=CV_SUBSCREEN;
12269 6 dword section_size=0;
12270
12271 //section id
12272
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12273 {
12274 new_return(1);
12275 }
12276
12277 //section version info
12278
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12279 {
12280 new_return(2);
12281 }
12282
12283
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12284 {
12285 new_return(3);
12286 }
12287
12288
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12289 {
12290 12 fake_pack_writing=(writecycle==0);
12291
12292 //section size
12293
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12294 {
12295 new_return(4);
12296 }
12297
12298 12 writesize=0;
12299
12300 12 byte sz = subscreens_active.size();
12301
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12302 new_return(5);
12303
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for(int32_t i=0; i<sz; i++)
12304 {
12305 66 int32_t ret = subscreens_active[i].write(f);
12306 66 fake_pack_writing=(writecycle==0);
12307
12308
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(ret!=0)
12309 new_return(ret);
12310 66 }
12311
12312 12 sz = subscreens_passive.size();
12313
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12314 new_return(5);
12315
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12 times.
62 for(int32_t i=0; i<sz; i++)
12316 {
12317 50 int32_t ret = subscreens_passive[i].write(f);
12318 50 fake_pack_writing=(writecycle==0);
12319
12320
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ret!=0)
12321 new_return(ret);
12322 50 }
12323
12324 12 sz = subscreens_overlay.size();
12325
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12326 new_return(5);
12327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for(int32_t i=0; i<sz; i++)
12328 {
12329 int32_t ret = subscreens_overlay[i].write(f);
12330 fake_pack_writing=(writecycle==0);
12331
12332 if(ret!=0)
12333 new_return(ret);
12334 }
12335
12336
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12337 {
12338 6 section_size=writesize;
12339 6 }
12340 12 }
12341
12342
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12343 {
12344 char ebuf[80];
12345 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12346 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12347 }
12348
12349 6 new_return(0);
12350 6 }
12351
12352 extern script_data *ffscripts[NUMSCRIPTFFC];
12353 extern script_data *itemscripts[NUMSCRIPTITEM];
12354 extern script_data *guyscripts[NUMSCRIPTGUYS];
12355 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12356 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12357 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12358 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12359 extern script_data *playerscripts[NUMSCRIPTPLAYER];
12360 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12361 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12362 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12363 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12364 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12365
12366 6 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12367 {
12368 6 dword section_id = ID_FFSCRIPT;
12369 6 dword section_version = V_FFSCRIPT;
12370 6 dword section_cversion = CV_FFSCRIPT;
12371 6 dword section_size = 0;
12372 6 dword zasmmeta_version = METADATA_V;
12373 6 byte numscripts = 0;
12374 6 numscripts = numscripts; //to avoid unused variables warnings
12375
12376 //section id
12377
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12378 {
12379 new_return(1);
12380 }
12381
12382 //section version info
12383
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12384 {
12385 new_return(2);
12386 }
12387
12388
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12389 {
12390 new_return(3);
12391 }
12392
12393
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12394 {
12395 new_return(4);
12396 }
12397
12398
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12399 {
12400 12 fake_pack_writing=(writecycle==0);
12401
12402 //section size
12403
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12404 {
12405 new_return(5);
12406 }
12407
12408 12 writesize=0;
12409
12410
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12411 {
12412 6144 int32_t ret = write_one_ffscript(f, Header, i, &ffscripts[i]);
12413 6144 fake_pack_writing=(writecycle==0);
12414
12415
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12416 {
12417 new_return(ret);
12418 }
12419 6144 }
12420
12421
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12422 {
12423 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemscripts[i]);
12424 3072 fake_pack_writing=(writecycle==0);
12425
12426
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12427 {
12428 new_return(ret);
12429 }
12430 3072 }
12431
12432
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12433 {
12434 3072 int32_t ret = write_one_ffscript(f, Header, i, &guyscripts[i]);
12435 3072 fake_pack_writing=(writecycle==0);
12436
12437
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12438 {
12439 new_return(ret);
12440 }
12441 3072 }
12442
12443
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12444
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12445 {
12446 3072 int32_t ret = write_one_ffscript(f, Header, i, &fake);
12447 3072 fake_pack_writing=(writecycle==0);
12448
12449
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12450 {
12451 new_return(ret);
12452 }
12453 3072 }
12454
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12455
12456
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12457 {
12458 3072 int32_t ret = write_one_ffscript(f, Header, i, &screenscripts[i]);
12459 3072 fake_pack_writing=(writecycle==0);
12460
12461
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12462 {
12463 new_return(ret);
12464 }
12465 3072 }
12466
12467
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12468 {
12469 96 int32_t ret = write_one_ffscript(f, Header, i, &globalscripts[i]);
12470 96 fake_pack_writing=(writecycle==0);
12471
12472
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12473 {
12474 new_return(ret);
12475 }
12476 96 }
12477
12478
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTPLAYER; i++)
12479 {
12480 60 int32_t ret = write_one_ffscript(f, Header, i, &playerscripts[i]);
12481 60 fake_pack_writing=(writecycle==0);
12482
12483
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12484 {
12485 new_return(ret);
12486 }
12487 60 }
12488
12489
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12490 {
12491 3072 int32_t ret = write_one_ffscript(f, Header, i, &lwpnscripts[i]);
12492 3072 fake_pack_writing=(writecycle==0);
12493
12494
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12495 {
12496 new_return(ret);
12497 }
12498 3072 }
12499
12500
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12501 {
12502 3072 int32_t ret = write_one_ffscript(f, Header, i, &ewpnscripts[i]);
12503 3072 fake_pack_writing=(writecycle==0);
12504
12505
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12506 {
12507 new_return(ret);
12508 }
12509 3072 }
12510
12511
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12512 {
12513 3072 int32_t ret = write_one_ffscript(f, Header, i, &dmapscripts[i]);
12514 3072 fake_pack_writing=(writecycle==0);
12515
12516
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12517 {
12518 new_return(ret);
12519 }
12520 3072 }
12521
12522
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12523 {
12524 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemspritescripts[i]);
12525 3072 fake_pack_writing=(writecycle==0);
12526
12527
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12528 {
12529 new_return(ret);
12530 }
12531 3072 }
12532
12533
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12534 {
12535 6144 int32_t ret = write_one_ffscript(f, Header, i, &comboscripts[i]);
12536 6144 fake_pack_writing=(writecycle==0);
12537
12538
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12539 {
12540 new_return(ret);
12541 }
12542 6144 }
12543
12544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12545 {
12546 new_return(2000);
12547 }
12548
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12549 {
12550 6144 int32_t ret = write_one_ffscript(f, Header, i, &genericscripts[i]);
12551 6144 fake_pack_writing=(writecycle==0);
12552
12553
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12554 {
12555 new_return(ret);
12556 }
12557 6144 }
12558
12559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12560 {
12561 new_return(2001);
12562 }
12563
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12564 {
12565 3072 int32_t ret = write_one_ffscript(f, Header, i, &subscreenscripts[i]);
12566 3072 fake_pack_writing=(writecycle==0);
12567
12568
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12569 {
12570 new_return(ret);
12571 }
12572 3072 }
12573
12574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12575 {
12576 new_return(2001);
12577 }
12578
12579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12580 {
12581 new_return(2002);
12582 }
12583
12584 12 word numffcbindings=0;
12585
12586
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12587 {
12588
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12589 {
12590 200 numffcbindings++;
12591 200 }
12592 6132 }
12593
12594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12595 {
12596 new_return(2003);
12597 }
12598
12599
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12600 {
12601
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12602 {
12603
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputw(it->first,f))
12604 {
12605 new_return(2004);
12606 }
12607
12608
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12609 {
12610 new_return(2005);
12611 }
12612
12613
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12614 {
12615 new_return(2006);
12616 }
12617 200 }
12618 6132 }
12619
12620 12 word numglobalbindings=0;
12621
12622
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12623 {
12624
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12625 {
12626 24 numglobalbindings++;
12627 24 }
12628 96 }
12629
12630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12631 {
12632 new_return(2007);
12633 }
12634
12635
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12636 {
12637
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12638 {
12639
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12640 {
12641 new_return(2008);
12642 }
12643
12644
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12645 {
12646 new_return(2009);
12647 }
12648
12649
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12650 {
12651 new_return(2010);
12652 }
12653 24 }
12654 96 }
12655
12656 12 word numitembindings=0;
12657
12658
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12659 {
12660
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12661 {
12662 24 numitembindings++;
12663 24 }
12664 3060 }
12665
12666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12667 {
12668 new_return(2011);
12669 }
12670
12671
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12672 {
12673
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12674 {
12675
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12676 {
12677 new_return(2012);
12678 }
12679
12680
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12681 {
12682 new_return(2013);
12683 }
12684
12685
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12686 {
12687 new_return(2014);
12688 }
12689 24 }
12690 3060 }
12691
12692 //new script types
12693 //npc scripts
12694 12 word numnpcbindings=0;
12695
12696
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12697 {
12698
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12699 {
12700 numnpcbindings++;
12701 }
12702 3060 }
12703
12704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12705 {
12706 new_return(2015);
12707 }
12708
12709
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12710 {
12711
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12712 {
12713 if(!p_iputw(it->first,f))
12714 {
12715 new_return(2016);
12716 }
12717
12718 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12719 {
12720 new_return(2017);
12721 }
12722
12723 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12724 {
12725 new_return(2018);
12726 }
12727 }
12728 3060 }
12729
12730 //lweapon
12731
12732 12 word numlwpnbindings=0;
12733
12734
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12735 {
12736
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12737 {
12738 numlwpnbindings++;
12739 }
12740 3060 }
12741
12742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12743 {
12744 new_return(2019);
12745 }
12746
12747
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12748 {
12749
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12750 {
12751 if(!p_iputw(it->first,f))
12752 {
12753 new_return(2020);
12754 }
12755
12756 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12757 {
12758 new_return(2021);
12759 }
12760
12761 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12762 {
12763 new_return(2022);
12764 }
12765 }
12766 3060 }
12767
12768 //////
12769
12770 //eweapon
12771
12772
12773 12 word numewpnbindings=0;
12774
12775
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12776 {
12777
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12778 {
12779 numewpnbindings++;
12780 }
12781 3060 }
12782
12783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12784 {
12785 new_return(2023);
12786 }
12787
12788
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12789 {
12790
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12791 {
12792 if(!p_iputw(it->first,f))
12793 {
12794 new_return(2024);
12795 }
12796
12797 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12798 {
12799 new_return(2025);
12800 }
12801
12802 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12803 {
12804 new_return(2026);
12805 }
12806 }
12807 3060 }
12808
12809 //player scripts
12810 12 word numherobindings=0;
12811
12812
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12813 {
12814
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12815 {
12816 2 numherobindings++;
12817 2 }
12818 48 }
12819
12820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12821 {
12822 new_return(2027);
12823 }
12824
12825
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12826 {
12827
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12828 {
12829
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12830 {
12831 new_return(2028);
12832 }
12833
12834
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12835 {
12836 new_return(2029);
12837 }
12838
12839
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12840 {
12841 new_return(2030);
12842 }
12843 2 }
12844 48 }
12845
12846 //dmap scripts
12847 12 word numdmapbindings=0;
12848
12849
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12850 {
12851
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12852 {
12853 4 numdmapbindings++;
12854 4 }
12855 3060 }
12856
12857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12858 {
12859 new_return(2031);
12860 }
12861
12862
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12863 {
12864
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12865 {
12866
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12867 {
12868 new_return(2032);
12869 }
12870
12871
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12872 {
12873 new_return(2033);
12874 }
12875
12876
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12877 {
12878 new_return(2034);
12879 }
12880 4 }
12881 3060 }
12882
12883 //screen scripts
12884 12 word numscreenbindings=0;
12885
12886
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12887 {
12888
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12889 {
12890 16 numscreenbindings++;
12891 16 }
12892 3060 }
12893
12894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12895 {
12896 new_return(2035);
12897 }
12898
12899
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12900 {
12901
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12902 {
12903
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputw(it->first,f))
12904 {
12905 new_return(2036);
12906 }
12907
12908
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12909 {
12910 new_return(2037);
12911 }
12912
12913
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12914 {
12915 new_return(2038);
12916 }
12917 16 }
12918 3060 }
12919 //item sprite scripts
12920 12 word numitemspritebindings=0;
12921
12922
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12923 {
12924
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12925 {
12926 numitemspritebindings++;
12927 }
12928 3060 }
12929
12930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12931 {
12932 new_return(2039);
12933 }
12934
12935
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12936 {
12937
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12938 {
12939 if(!p_iputw(it->first,f))
12940 {
12941 new_return(2040);
12942 }
12943
12944 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12945 {
12946 new_return(2041);
12947 }
12948
12949 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12950 {
12951 new_return(2042);
12952 }
12953 }
12954 3060 }
12955
12956 //combo scripts
12957 12 word numcombobindings=0;
12958
12959
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12960 {
12961
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12962 {
12963 numcombobindings++;
12964 }
12965 6132 }
12966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12967 {
12968 new_return(2043);
12969 }
12970
12971
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12972 {
12973
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12974 {
12975 if(!p_iputw(it->first,f))
12976 {
12977 new_return(2044);
12978 }
12979
12980 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12981 {
12982 new_return(2045);
12983 }
12984
12985 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12986 {
12987 new_return(2046);
12988 }
12989 }
12990 6132 }
12991 //subscreen scripts
12992 12 word numgenericbindings=0;
12993
12994
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12995 {
12996
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12997 {
12998 numgenericbindings++;
12999 }
13000 6132 }
13001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
13002 {
13003 new_return(2043);
13004 }
13005
13006
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13007 {
13008
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
13009 {
13010 if(!p_iputw(it->first,f))
13011 {
13012 new_return(2044);
13013 }
13014
13015 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13016 {
13017 new_return(2045);
13018 }
13019
13020 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13021 {
13022 new_return(2046);
13023 }
13024 }
13025 6132 }
13026
13027 //generic scripts
13028 12 word numsubscreenbindings=0;
13029
13030
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13031 {
13032
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13033 {
13034 numsubscreenbindings++;
13035 }
13036 3060 }
13037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
13038 {
13039 new_return(2047);
13040 }
13041
13042
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13043 {
13044
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13045 {
13046 if(!p_iputw(it->first,f))
13047 {
13048 new_return(2048);
13049 }
13050
13051 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13052 {
13053 new_return(2049);
13054 }
13055
13056 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13057 {
13058 new_return(2050);
13059 }
13060 }
13061 3060 }
13062
13063
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13064 {
13065 6 section_size=writesize;
13066 6 }
13067 12 }
13068
13069
13070
13071
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13072 {
13073 char ebuf[80];
13074 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13075 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13076 }
13077
13078 6 new_return(0);
13079 //return 0; //this is just here to stomp the compiler from whining.
13080 //the irony is that it causes an "unreachable code" warning.
13081 6 }
13082
13083 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data **script)
13084 {
13085 //these are here to bypass compiler warnings about unused arguments
13086 46236 Header=Header;
13087 46236 i=i;
13088
13089
2/2
✓ Branch 0 taken 9494 times.
✓ Branch 1 taken 36742 times.
46236 size_t num_commands = (*script)->zasm_script ? (*script)->zasm_script->size : 0;
13090
13091
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputl(num_commands,f))
13092 {
13093 new_return(6);
13094 }
13095
13096 //Metadata
13097 46236 zasm_meta const& tmeta = (*script)->meta;
13098
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.zasm_v,f))
13099 {
13100 new_return(7);
13101 }
13102
13103
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.meta_v,f))
13104 {
13105 new_return(8);
13106 }
13107
13108
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.ffscript_v,f))
13109 {
13110 new_return(9);
13111 }
13112
13113
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc((int)tmeta.script_type,f))
13114 {
13115 new_return(10);
13116 }
13117
13118
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13119 {
13120
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.run_idens[q],f))
13121 new_return(11);
13122 369888 }
13123
13124
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13125 {
13126
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.run_types[q],f))
13127 {
13128 new_return(12);
13129 }
13130 369888 }
13131
13132
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc(tmeta.flags,f))
13133 {
13134 new_return(13);
13135 }
13136
13137
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v1,f))
13138 {
13139 new_return(14);
13140 }
13141
13142
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v2,f))
13143 {
13144 new_return(15);
13145 }
13146
13147
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v3,f))
13148 {
13149 new_return(16);
13150 }
13151
13152
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v4,f))
13153 {
13154 new_return(17);
13155 }
13156
13157
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putcstr(tmeta.script_name,f))
13158 new_return(18);
13159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46236 times.
46236 if(!p_putcstr(tmeta.author,f))
13160 new_return(19);
13161
2/2
✓ Branch 0 taken 462360 times.
✓ Branch 1 taken 46236 times.
508596 for(auto q = 0; q < 10; ++q)
13162 {
13163
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putcstr(tmeta.attributes[q],f))
13164 new_return(27);
13165
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putwstr(tmeta.attributes_help[q],f))
13166 new_return(28);
13167 462360 }
13168
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13169 {
13170
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attribytes[q],f))
13171 new_return(29);
13172
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attribytes_help[q],f))
13173 new_return(30);
13174 369888 }
13175
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13176 {
13177
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attrishorts[q],f))
13178 new_return(31);
13179
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13180 new_return(32);
13181 369888 }
13182
2/2
✓ Branch 0 taken 739776 times.
✓ Branch 1 taken 46236 times.
786012 for(auto q = 0; q < 16; ++q)
13183 {
13184
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putcstr(tmeta.usrflags[q],f))
13185 new_return(33);
13186
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putwstr(tmeta.usrflags_help[q],f))
13187 new_return(34);
13188 739776 }
13189
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13190 {
13191
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.initd[q],f))
13192 new_return(35);
13193
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.initd_help[q],f))
13194 new_return(36);
13195 369888 }
13196
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13197 {
13198
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.initd_type[q],f))
13199 new_return(37);
13200 369888 }
13201
13202
2/2
✓ Branch 0 taken 36742 times.
✓ Branch 1 taken 626442 times.
663184 for(int32_t j=0; j<num_commands; j++)
13203 {
13204 626442 auto& zas = (*script)->zasm_script->zasm[j];
13205
1/2
✓ Branch 0 taken 626442 times.
✗ Branch 1 not taken.
626442 if(!p_iputw(zas.command,f))
13206 {
13207 new_return(20);
13208 }
13209
13210
2/2
✓ Branch 0 taken 616948 times.
✓ Branch 1 taken 9494 times.
626442 if(zas.command==0xFFFF)
13211 {
13212 9494 break;
13213 }
13214 else
13215 {
13216
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg1,f))
13217 {
13218 new_return(21);
13219 }
13220
13221
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg2,f))
13222 {
13223 new_return(22);
13224 }
13225
13226
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg3,f))
13227 {
13228 new_return(23);
13229 }
13230
13231 616948 uint32_t sz = 0;
13232
2/2
✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 614178 times.
616948 if(zas.strptr)
13233 2770 sz = zas.strptr->size();
13234
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13235 {
13236 new_return(23);
13237 }
13238
2/2
✓ Branch 0 taken 614178 times.
✓ Branch 1 taken 2770 times.
616948 if(sz)
13239 {
13240 2770 auto& str = *zas.strptr;
13241
2/2
✓ Branch 0 taken 222648 times.
✓ Branch 1 taken 2770 times.
225418 for(size_t q = 0; q < sz; ++q)
13242 {
13243
1/2
✓ Branch 0 taken 222648 times.
✗ Branch 1 not taken.
222648 if(!p_putc(str[q],f))
13244 {
13245 new_return(24);
13246 }
13247 222648 }
13248 2770 }
13249 616948 sz = 0;
13250
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(zas.vecptr)
13251 114 sz = zas.vecptr->size();
13252
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13253 {
13254 new_return(25);
13255 }
13256
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(sz) //vector found
13257 {
13258 114 auto& vec = *zas.vecptr;
13259
2/2
✓ Branch 0 taken 850 times.
✓ Branch 1 taken 114 times.
964 for(size_t q = 0; q < sz; ++q)
13260 {
13261
1/2
✓ Branch 0 taken 850 times.
✗ Branch 1 not taken.
850 if(!p_iputl(vec[q],f))
13262 {
13263 new_return(26);
13264 }
13265 850 }
13266 114 }
13267 }
13268 616948 }
13269
13270 46236 new_return(0);
13271 }
13272
13273 extern SAMPLE customsfxdata[WAV_COUNT];
13274 extern uint8_t customsfxflag[WAV_COUNT>>3];
13275
13276 6 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13277 {
13278 //these are here to bypass compiler warnings about unused arguments
13279 6 Header=Header;
13280
13281 6 dword section_id=ID_SFX;
13282 6 dword section_version=V_SFX;
13283 6 dword section_cversion=CV_SFX;
13284 6 dword section_size=0;
13285
13286 //section id
13287
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13288 {
13289 new_return(1);
13290 }
13291
13292 //section version info
13293
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13294 {
13295 new_return(2);
13296 }
13297
13298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13299 {
13300 new_return(3);
13301 }
13302
13303
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13304 {
13305 12 fake_pack_writing=(writecycle==0);
13306
13307 //section size
13308
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13309 {
13310 new_return(4);
13311 }
13312
13313 12 writesize=0;
13314
13315
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13316 {
13317
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(customsfxflag[i],f))
13318 {
13319 new_return(5);
13320 }
13321 384 }
13322
13323
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13324 {
13325
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13326 2240 continue;
13327
13328
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!pfwrite(sfx_string[i], 36, f))
13329 {
13330 new_return(5);
13331 }
13332 820 }
13333
13334
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13335 {
13336
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13337 2240 continue;
13338
13339
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].bits,f))
13340 {
13341 new_return(5);
13342 }
13343
13344
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].stereo,f))
13345 {
13346 new_return(6);
13347 }
13348
13349
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].freq,f))
13350 {
13351 new_return(7);
13352 }
13353
13354
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].priority,f))
13355 {
13356 new_return(8);
13357 }
13358
13359
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].len,f))
13360 {
13361 new_return(9);
13362 }
13363
13364
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_start,f))
13365 {
13366 new_return(10);
13367 }
13368
13369
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_end,f))
13370 {
13371 new_return(11);
13372 }
13373
13374
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].param,f))
13375 {
13376 new_return(12);
13377 }
13378
13379 //de-endianfy the data
13380 820 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13381
13382
2/2
✓ Branch 0 taken 18594894 times.
✓ Branch 1 taken 820 times.
18595714 for(int32_t j=0; j<wordstowrite; j++)
13383 {
13384
1/2
✓ Branch 0 taken 18594894 times.
✗ Branch 1 not taken.
18594894 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13385 {
13386 new_return(13);
13387 }
13388 18594894 }
13389 820 }
13390
13391
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13392 {
13393 6 section_size=writesize;
13394 6 }
13395 12 }
13396
13397
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13398 {
13399 char ebuf[80];
13400 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13401 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13402 }
13403
13404 6 new_return(0);
13405 }
13406
13407 6 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13408 {
13409 6 dword section_id=ID_INITDATA;
13410 6 dword section_version=V_INITDATA;
13411 6 dword section_cversion=CV_INITDATA;
13412 6 dword section_size = 0;
13413
13414 6 zinit.last_map=Map.getCurrMap();
13415 6 zinit.last_screen=Map.getCurrScr();
13416 6 zinit.normalize();
13417
13418 //section id
13419
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13420 {
13421 new_return(1);
13422 }
13423
13424 //section version info
13425
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13426 {
13427 new_return(2);
13428 }
13429
13430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13431 {
13432 new_return(3);
13433 }
13434
13435 //TODO
13436
13437
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13438 {
13439 12 fake_pack_writing=(writecycle==0);
13440
13441 //section size
13442
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13443 new_return(4);
13444
13445 12 writesize=0;
13446
13447
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int q = 0; q < MAXITEMS/8; ++q)
13448
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(zinit.items[q], f))
13449 new_return(5);
13450
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(int q = 0; q < MAXLEVELS/8; ++q)
13451 {
13452
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.map[q], f))
13453 new_return(6);
13454
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.compass[q], f))
13455 new_return(7);
13456
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.boss_key[q], f))
13457 new_return(8);
13458
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.mcguffin[q], f))
13459 new_return(9);
13460 768 }
13461
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbvec(zinit.level_keys, f))
13462 new_return(10);
13463
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(MAX_COUNTERS,f))
13464 new_return(11);
13465
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13466
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.counter[q],f))
13467 new_return(12);
13468
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13469
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.mcounter[q],f))
13470 new_return(13);
13471
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.bomb_ratio,f))
13472 new_return(14);
13473
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp,f))
13474 new_return(15);
13475
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp_per_hc,f))
13476 new_return(16);
13477
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.cont_heart,f))
13478 new_return(17);
13479
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hp_per_heart,f))
13480 new_return(18);
13481
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magic_per_block,f))
13482 new_return(19);
13483
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_damage_multiplier,f))
13484 new_return(20);
13485
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.ene_damage_multiplier,f))
13486 new_return(21);
13487
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_type,f))
13488 new_return(22);
13489
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_arg,f))
13490 new_return(23);
13491
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_percent,f))
13492 new_return(24);
13493
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.def_lightrad,f))
13494 new_return(25);
13495
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.transdark_percent,f))
13496 new_return(26);
13497
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.darkcol,f))
13498 new_return(27);
13499
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_x,f))
13500 new_return(28);
13501
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_y,f))
13502 new_return(29);
13503
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_xofs,f))
13504 new_return(30);
13505
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_yofs,f))
13506 new_return(31);
13507
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_color,f))
13508 new_return(32);
13509
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_1_color,f))
13510 new_return(33);
13511
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_2_color,f))
13512 new_return(34);
13513
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_flags,f))
13514 new_return(35);
13515
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.flags,f))
13516 new_return(36);
13517
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_map,f))
13518 new_return(37);
13519
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_screen,f))
13520 new_return(38);
13521
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_x,f))
13522 new_return(39);
13523
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_y,f))
13524 new_return(40);
13525
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_is_offset,f))
13526 new_return(41);
13527
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_speed,f))
13528 new_return(42);
13529
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.gravity,f))
13530 new_return(43);
13531
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.swimgravity,f))
13532 new_return(44);
13533
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.terminalv,f))
13534 new_return(45);
13535
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_speed,f))
13536 new_return(46);
13537
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_mult,f))
13538 new_return(47);
13539
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_div,f))
13540 new_return(48);
13541
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimUpStep,f))
13542 new_return(49);
13543
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimSideStep,f))
13544 new_return(50);
13545
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimDownStep,f))
13546 new_return(51);
13547
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.exitWaterJump,f))
13548 new_return(52);
13549
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroStep,f))
13550 new_return(53);
13551
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.heroAnimationStyle,f))
13552 new_return(54);
13553
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.jump_hero_layer_threshold,f))
13554 new_return(55);
13555
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.bunny_ltm,f))
13556 new_return(56);
13557
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.start_dmap,f))
13558 new_return(57);
13559
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.subscrSpeed,f))
13560 new_return(58);
13561
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.switchhookstyle,f))
13562 new_return(59);
13563
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magicdrainrate,f))
13564 new_return(60);
13565
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputzf(zinit.shove_offset,f))
13566 new_return(61);
13567
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.gen_doscript, f))
13568 new_return(62);
13569
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_exitState, f))
13570 new_return(63);
13571
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_reloadState, f))
13572 new_return(64);
13573
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_initd, f))
13574 new_return(65);
13575
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_eventstate, f))
13576 new_return(66);
13577
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_data, f))
13578 new_return(67);
13579
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.screen_data, f))
13580 new_return(68);
13581
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickerspeed, f))
13582 new_return(69);
13583
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickercolor, f))
13584 new_return(70);
13585
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickertransp, f))
13586 new_return(71);
13587
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputzf(zinit.air_drag, f))
13588 new_return(72);
13589
13590
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13591 {
13592 6 section_size=writesize;
13593 6 }
13594 12 }
13595
13596
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13597 {
13598 char ebuf[80];
13599 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13600 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13601 }
13602
13603 6 new_return(0);
13604 }
13605
13606 6 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
13607 {
13608 //these are here to bypass compiler warnings about unused arguments
13609 6 Header=Header;
13610
13611 6 dword section_id=ID_ITEMDROPSETS;
13612 6 dword section_version=V_ITEMDROPSETS;
13613 6 dword section_cversion=CV_ITEMDROPSETS;
13614 // dword section_size=0;
13615 6 dword section_size = 0;
13616 6 word num_item_drop_sets=count_item_drop_sets();
13617
13618 //section id
13619
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13620 {
13621 new_return(1);
13622 }
13623
13624 //section version info
13625
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13626 {
13627 new_return(2);
13628 }
13629
13630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13631 {
13632 new_return(3);
13633 }
13634
13635
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13636 {
13637 12 fake_pack_writing=(writecycle==0);
13638
13639 //section size
13640
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13641 {
13642 new_return(4);
13643 }
13644
13645 12 writesize=0;
13646
13647 //finally... section data
13648
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_item_drop_sets,f))
13649 {
13650 new_return(5);
13651 }
13652
13653
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 12 times.
170 for(int32_t i=0; i<num_item_drop_sets; i++)
13654 {
13655
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
13656 {
13657 new_return(6);
13658 }
13659
13660
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 158 times.
1738 for(int32_t j=0; j<10; ++j)
13661 {
13662
1/2
✓ Branch 0 taken 1580 times.
✗ Branch 1 not taken.
1580 if(!p_iputw(item_drop_sets[i].item[j],f))
13663 {
13664 new_return(7);
13665 }
13666 1580 }
13667
13668
2/2
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 158 times.
1896 for(int32_t j=0; j<11; ++j)
13669 {
13670
1/2
✓ Branch 0 taken 1738 times.
✗ Branch 1 not taken.
1738 if(!p_iputw(item_drop_sets[i].chance[j],f))
13671 {
13672 new_return(8);
13673 }
13674 1738 }
13675 158 }
13676
13677
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13678 {
13679 6 section_size=writesize;
13680 6 }
13681 12 }
13682
13683
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13684 {
13685 char ebuf[80];
13686 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13687 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13688 }
13689
13690 6 new_return(0);
13691 }
13692
13693 6 int32_t writefavorites(PACKFILE *f, zquestheader*)
13694 {
13695 6 dword section_id=ID_FAVORITES;
13696 6 dword section_version=V_FAVORITES;
13697 6 dword section_cversion=CV_FAVORITES;
13698 6 dword section_size = 0;
13699
13700 //section id
13701
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13702 {
13703 new_return(1);
13704 }
13705
13706 //section version info
13707
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13708 {
13709 new_return(2);
13710 }
13711
13712
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13713 {
13714 new_return(3);
13715 }
13716
13717
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13718 {
13719 12 fake_pack_writing=(writecycle==0);
13720
13721 //section size
13722
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13723 new_return(4);
13724
13725 12 writesize=0;
13726
13727
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
13728 new_return(16);
13729
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
13730 new_return(17);
13731
13732 12 word favcmb_cnt = 0;
13733
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14918 times.
14922 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
13734
2/2
✓ Branch 0 taken 14910 times.
✓ Branch 1 taken 8 times.
14918 if(favorite_combos[q] != -1)
13735 {
13736 8 favcmb_cnt = q+1;
13737 8 break;
13738 }
13739
13740
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
13741 new_return(5);
13742
13743
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 12 times.
222 for(int i=0; i<favcmb_cnt; ++i)
13744 {
13745
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_putc(favorite_combo_modes[i], f))
13746 new_return(6);
13747
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_iputl(favorite_combos[i], f))
13748 new_return(7);
13749 210 }
13750
13751
13752 12 word max_combo_cols = MAX_COMBO_COLS;
13753
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_combo_cols,f))
13754 new_return(9);
13755
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int q = 0; q < max_combo_cols; ++q)
13756 {
13757
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(First[q],f))
13758 new_return(10);
13759
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_alistpos[q],f))
13760 new_return(11);
13761
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_pool_listpos[q],f))
13762 new_return(12);
13763 48 }
13764 12 word max_mappages = MAX_MAPPAGE_BTNS;
13765
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_mappages,f))
13766 new_return(13);
13767
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(int q = 0; q < max_mappages; ++q)
13768 {
13769
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].map,f))
13770 new_return(14);
13771
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].screen,f))
13772 new_return(15);
13773 108 }
13774
13775
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13776 {
13777 6 section_size=writesize;
13778 6 }
13779 12 }
13780
13781
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13782 {
13783 char ebuf[80];
13784 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13785 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13786 }
13787
13788 6 new_return(0);
13789 }
13790
13791 6 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
13792 {
13793
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!afname) afname = filename;
13794 6 reset_combo_animations();
13795 6 reset_combo_animations2();
13796 6 strcpy(header.id_str,QH_NEWIDSTR);
13797 6 header.zelda_version = ZELDA_VERSION;
13798 6 header.internal = INTERNAL_VERSION;
13799 // header.str_count = msg_count;
13800 // header.data_flags[ZQ_TILES] = usetiles;
13801 6 header.data_flags[ZQ_TILES] = true;
13802 6 header.data_flags[ZQ_CHEATS2] = 1;
13803 6 header.build=VERSION_BUILD;
13804
13805
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 6 times.
1518 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
13806 {
13807 1512 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
13808 1512 }
13809
13810 char zinfofilename[2048];
13811 6 replace_extension(zinfofilename, afname, "zinfo", 2047);
13812
13813 6 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
13814 6 box_out("Saving Quest...");
13815 6 box_eol();
13816 6 box_eol();
13817
13818
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string tmp_filename = util::create_temp_file_path(filename);
13819
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
13820
13821
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!f)
13822 return 1;
13823
13824
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Header...");
13825
13826
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeheader(f,&header)!=0)
13827 return 2;
13828
13829
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13830
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13831
13832
13833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(header.external_zinfo)
13834 {
13835 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
13836
13837 box_out("Writing ZInfo...");
13838 if(inf)
13839 {
13840 if(writezinfo(inf,ZI)!=0)
13841 return 2;
13842
13843 pack_fclose(inf);
13844 box_out("okay.");
13845 }
13846 else box_out(" ...file failure");
13847 box_eol();
13848 }
13849 else
13850 {
13851
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing ZInfo...");
13852
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writezinfo(f,ZI)!=0)
13853 return 2;
13854
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13855
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13856 }
13857
13858
13859
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Rules...");
13860
13861
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writerules(f,&header)!=0)
13862 return 3;
13863
13864
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13865
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13866
13867
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Strings...");
13868
13869
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
13870 return 4;
13871
13872
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13873
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13874
13875
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Doors...");
13876
13877
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedoorcombosets(f,&header)!=0)
13878 return 5;
13879
13880
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13881
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13882
13883
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing DMaps...");
13884
13885
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
13886 return 6;
13887
13888
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13889
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13890
13891
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Data...");
13892
13893
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemisc(f,&header)!=0)
13894 return 7;
13895
13896
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13897
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13898
13899
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Colors...");
13900
13901
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemisccolors(f,&header)!=0)
13902 return 8;
13903
13904
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13905
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13906
13907
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Game Icons...");
13908
13909
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writegameicons(f,&header)!=0)
13910 return 9;
13911
13912
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13913
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13914
13915
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Items...");
13916
13917
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeitems(f,&header)!=0)
13918 return 10;
13919
13920
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13921
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13922
13923
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Weapons...");
13924
13925
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeweapons(f,&header)!=0)
13926 return 11;
13927
13928
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13929
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13930
13931
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Maps...");
13932
13933
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemaps(f,&header)!=0)
13934 return 12;
13935
13936
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13937
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13938
13939
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combos...");
13940
13941
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
13942 return 13;
13943
13944
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13945
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13946
13947
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combo Aliases...");
13948
13949
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
13950 return 14;
13951
13952
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13953
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13954
13955
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Color Data...");
13956
13957
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
13958 return 15;
13959
13960
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13961
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13962
13963
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Tiles...");
13964
13965
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
13966 return 16;
13967
13968
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13969
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13970
13971
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing MIDIs...");
13972
13973
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemidis(f)!=0)
13974 return 17;
13975
13976
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13977
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13978
13979
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Cheat Codes...");
13980
13981
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecheats(f,&header)!=0)
13982 return 18;
13983
13984
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13985
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13986
13987
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Init. Data...");
13988
13989
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeinitdata(f,&header)!=0)
13990 return 19;
13991
13992
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13993
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13994
13995
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Guy Data...");
13996
13997
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeguys(f,&header)!=0)
13998 return 20;
13999
14000
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14001
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14002
14003
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Player Sprite Data...");
14004
14005
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeherosprites(f,&header)!=0)
14006 return 21;
14007
14008
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14009
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14010
14011
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Subscreen Data...");
14012
14013
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesubscreens(f,&header)!=0)
14014 return 22;
14015
14016
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14017
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14018
14019
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing FF Script Data...");
14020
14021
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeffscript(f,&header)!=0)
14022 return 23;
14023
14024
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14025
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14026
14027
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing SFX Data...");
14028
14029
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesfx(f,&header)!=0)
14030 return 24;
14031
14032
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14033
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14034
14035
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Item Drop Sets...");
14036
14037
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeitemdropsets(f, &header)!=0)
14038 return 25;
14039
14040
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14041
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14042
14043
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Favorite Combos...");
14044
14045
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writefavorites(f, &header)!=0)
14046 return 26;
14047
14048
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14049
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14050
14051
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 pack_fclose(f);
14052
14053
14054
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if(header.use_keyfile&&header.dirty_password)
14055 {
14056 char const* kfname = filename;
14057 char keyfilename[2048]={0};
14058 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
14059
14060 char temp_pw[QSTPWD_LEN] = {0};
14061 uint ind = 0;
14062 for(char const* ext : {"key","zpwd","zcheat"})
14063 {
14064 replace_extension(keyfilename, kfname, ext, 2047);
14065 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14066 char msg[80] = {0};
14067 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14068 msg[78]=13;
14069 msg[79]=10;
14070 pfwrite(msg, 80, fp);
14071 p_iputw(header.zelda_version,fp);
14072 p_putc(header.build,fp);
14073 char const* pwd = header.password;
14074 if(ind == 2) //.zcheat, hashed pwd
14075 {
14076 char hashmap = 'Z';
14077 hashmap += 'Q';
14078 hashmap += 'U';
14079 hashmap += 'E';
14080 hashmap += 'S';
14081 hashmap += 'T';
14082 for ( int q = 0; q < QSTPWD_LEN; ++q )
14083 {
14084 temp_pw[q] = header.password[q];
14085 temp_pw[q] += hashmap;
14086 }
14087 pwd = temp_pw;
14088 }
14089 pfwrite(pwd, strlen(pwd), fp);
14090 pack_fclose(fp);
14091 ++ind;
14092 }
14093 }
14094
14095 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14096 6 std::error_code ec;
14097
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::rename(tmp_filename, filename, ec);
14098
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ec)
14099 {
14100 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14101 return ec.value();
14102 }
14103
14104
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14105
14106 #ifdef __EMSCRIPTEN__
14107 em_sync_fs();
14108 #endif
14109
14110 6 return 0;
14111 6 }
14112
14113 // #ifdef _WIN32
14114 // static std::time_t to_time_t(FILETIME const& ft) {
14115 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14116 // t -= 116444736000000000ull;
14117 // t /= 10000000u;
14118 // return static_cast<std::time_t>(t);
14119 // }
14120 // #else
14121 // #endif
14122 template<typename TP>
14123 4 static std::time_t to_time_t(TP tp) {
14124 using namespace std::chrono;
14125 4 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14126 4 return system_clock::to_time_t(sctp);
14127 }
14128
14129 4 std::string get_time_last_modified_string(std::string path)
14130 {
14131
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto write_time = fs::last_write_time(path);
14132 // TODO: C++20 but not supported yet.
14133 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14134 4 std::time_t tt = to_time_t(write_time);
14135 4 std::tm *gmt = std::gmtime(&tt);
14136 4 std::stringstream buffer;
14137
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 buffer << std::put_time(gmt, "%Y-%m-%d");
14138
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string formattedFileTime = buffer.str();
14139 4 return formattedFileTime;
14140
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }
14141
14142 6 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14143 {
14144 // Always backup quest if it was last saved in a different version of the editor,
14145 // or if this a new file and is overwritting another qst file.
14146
10/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14147 {
14148 4 std::string backup_name;
14149
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string last_mod = get_time_last_modified_string(filename);
14150
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (strlen(header.zelda_version_string) > 0)
14151 {
14152
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14153 4 }
14154 else
14155 {
14156 backup_name = fmt::format("{}", last_mod);
14157 }
14158
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14159
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 fs::path backup_path = fs::path("backups") / backup_fname;
14160
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (!fs::exists(backup_path))
14161 {
14162
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 fs::create_directories(fs::path("backups"));
14163
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 if (fs::copy_file(filename, backup_path))
14164 {
14165
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14166 4 }
14167 else
14168 {
14169 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14170 }
14171 4 }
14172 4 }
14173
14174 6 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14175 6 fake_pack_writing = false;
14176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(ret)
14177 {
14178 box_out("-- Error saving quest file! --");
14179 box_end(true);
14180 }
14181 6 else box_end(false);
14182 6 return ret;
14183 }
14184
14185 6 int32_t save_quest(const char *filename, bool timed_save)
14186 {
14187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14188
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 bool compress=!(timed_save&&UncompressedAutoSaves);
14189 char ext1[5];
14190 6 ext1[0]=0;
14191
14192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(timed_save)
14193 {
14194 sprintf(ext1, "qt");
14195 }
14196 else
14197 {
14198 6 sprintf(ext1, "qb");
14199 }
14200
14201
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(retention)
14202 {
14203 char backupname[2048];
14204 char backupname2[2048];
14205 char ext[12];
14206
14207 for(int32_t i=retention-1; i>0; --i)
14208 {
14209 sprintf(ext, "%s%d", ext1, i-1);
14210 replace_extension(backupname, filepath, ext, 2047);
14211
14212 if(exists(backupname))
14213 {
14214 sprintf(ext, "%s%d", ext1, i);
14215 replace_extension(backupname2, filepath, ext, 2047);
14216
14217 if(exists(backupname2))
14218 {
14219 remove(backupname2);
14220 }
14221
14222 rename(backupname, backupname2);
14223 }
14224 }
14225
14226 //don't do this if we're not saving to the same name -DD
14227 if(!timed_save && !strcmp(filepath, filename))
14228 {
14229 sprintf(ext, "%s%d", ext1, 0);
14230 replace_extension(backupname, filepath, ext, 2047);
14231 rename(filepath, backupname);
14232 }
14233 }
14234
14235 int32_t ret;
14236 6 ret = save_unencoded_quest(filename, compress, filename);
14237
14238 6 return ret;
14239 }
14240
14241 6 void center_zq_class_dialogs()
14242 {
14243 6 jwin_center_dialog(pwd_dlg);
14244 6 }
14245
14246 void zmap::prv_secrets(bool high16only)
14247 {
14248 mapscr *s = &prvscr;
14249 mapscr *t = prvlayers;
14250 int32_t ft=0;
14251
14252 for(int32_t i=0; i<176; i++)
14253 {
14254 bool putit;
14255
14256 if(!high16only)
14257 {
14258 for(int32_t j=-1; j<6; j++)
14259 {
14260 int32_t newflag = -1;
14261
14262 for(int32_t iter=0; iter<2; ++iter)
14263 {
14264 putit=true;
14265
14266 if(!t[j].valid)
14267 continue;
14268
14269 int32_t checkflag=combobuf[t[j].data[i]].flag;
14270
14271 if(iter==1)
14272 {
14273 checkflag=t[j].sflag[i];
14274 }
14275
14276 switch(checkflag)
14277 {
14278 case mfANYFIRE:
14279 ft=sBCANDLE;
14280 break;
14281
14282 case mfSTRONGFIRE:
14283 ft=sRCANDLE;
14284 break;
14285
14286 case mfMAGICFIRE:
14287 ft=sWANDFIRE;
14288 break;
14289
14290 case mfDIVINEFIRE:
14291 ft=sDIVINEFIRE;
14292 break;
14293
14294 case mfARROW:
14295 ft=sARROW;
14296 break;
14297
14298 case mfSARROW:
14299 ft=sSARROW;
14300 break;
14301
14302 case mfGARROW:
14303 ft=sGARROW;
14304 break;
14305
14306 case mfSBOMB:
14307 ft=sSBOMB;
14308 break;
14309
14310 case mfBOMB:
14311 ft=sBOMB;
14312 break;
14313
14314 case mfBRANG:
14315 ft=sBRANG;
14316 break;
14317
14318 case mfMBRANG:
14319 ft=sMBRANG;
14320 break;
14321
14322 case mfFBRANG:
14323 ft=sFBRANG;
14324 break;
14325
14326 case mfWANDMAGIC:
14327 ft=sWANDMAGIC;
14328 break;
14329
14330 case mfREFMAGIC:
14331 ft=sREFMAGIC;
14332 break;
14333
14334 case mfREFFIREBALL:
14335 ft=sREFFIREBALL;
14336 break;
14337
14338 case mfSWORD:
14339 ft=sSWORD;
14340 break;
14341
14342 case mfWSWORD:
14343 ft=sWSWORD;
14344 break;
14345
14346 case mfMSWORD:
14347 ft=sMSWORD;
14348 break;
14349
14350 case mfXSWORD:
14351 ft=sXSWORD;
14352 break;
14353
14354 case mfSWORDBEAM:
14355 ft=sSWORDBEAM;
14356 break;
14357
14358 case mfWSWORDBEAM:
14359 ft=sWSWORDBEAM;
14360 break;
14361
14362 case mfMSWORDBEAM:
14363 ft=sMSWORDBEAM;
14364 break;
14365
14366 case mfXSWORDBEAM:
14367 ft=sXSWORDBEAM;
14368 break;
14369
14370 case mfHOOKSHOT:
14371 ft=sHOOKSHOT;
14372 break;
14373
14374 case mfWAND:
14375 ft=sWAND;
14376 break;
14377
14378 case mfHAMMER:
14379 ft=sHAMMER;
14380 break;
14381
14382 case mfSTRIKE:
14383 ft=sSTRIKE;
14384 break;
14385
14386 default:
14387 putit = false;
14388 break;
14389 }
14390
14391 if(putit)
14392 {
14393 if(j==-1)
14394 {
14395 s->data[i] = s->secretcombo[ft];
14396 s->cset[i] = s->secretcset[ft];
14397 newflag = s->secretflag[ft];
14398 }
14399 else
14400 {
14401 t[j].data[i] = t[j].secretcombo[ft];
14402 t[j].cset[i] = t[j].secretcset[ft];
14403 newflag = t[j].secretflag[ft];
14404 }
14405 }
14406 }
14407
14408 if(newflag >-1)
14409 {
14410 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14411 }
14412 }
14413 }
14414
14415 //if(true)
14416 //{
14417 int32_t newflag = -1;
14418
14419 for(int32_t iter=0; iter<2; ++iter)
14420 {
14421 int32_t checkflag=combobuf[s->data[i]].flag;
14422
14423 if(iter==1)
14424 {
14425 checkflag=s->sflag[i];
14426 }
14427
14428 if((checkflag > 15)&&(checkflag < 32))
14429 {
14430 s->data[i] = s->secretcombo[(checkflag)-16+4];
14431 s->cset[i] = s->secretcset[(checkflag)-16+4];
14432 newflag = s->secretflag[(checkflag)-16+4];
14433 // putit = true;
14434 }
14435 }
14436
14437 if(newflag >-1) s->sflag[i] = newflag;
14438
14439 for(int32_t j=0; j<6; j++)
14440 {
14441 if(!t[j].valid) continue;
14442
14443 int32_t newflag2 = -1;
14444
14445 for(int32_t iter=0; iter<2; ++iter)
14446 {
14447 int32_t checkflag=combobuf[t[j].data[i]].flag;
14448
14449 if(iter==1)
14450 {
14451 checkflag=t[j].sflag[i];
14452 }
14453
14454 if((checkflag > 15)&&(checkflag < 32))
14455 {
14456 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14457 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14458 newflag2 = t[j].secretflag[(checkflag)-16+4];
14459 }
14460 }
14461
14462 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14463 }
14464 }
14465
14466 //FFCs
14467 word c = s->numFFC();
14468 for(word i=0; i<c; ++i)
14469 {
14470 bool putit;
14471
14472 if(!high16only)
14473 {
14474 for(int32_t iter=0; iter<1; ++iter)
14475 {
14476 putit=true;
14477 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14478
14479 if(iter==1)
14480 {
14481 checkflag=s->sflag[i];
14482 }
14483
14484 switch(checkflag)
14485 {
14486 case mfANYFIRE:
14487 ft=sBCANDLE;
14488 break;
14489
14490 case mfSTRONGFIRE:
14491 ft=sRCANDLE;
14492 break;
14493
14494 case mfMAGICFIRE:
14495 ft=sWANDFIRE;
14496 break;
14497
14498 case mfDIVINEFIRE:
14499 ft=sDIVINEFIRE;
14500 break;
14501
14502 case mfARROW:
14503 ft=sARROW;
14504 break;
14505
14506 case mfSARROW:
14507 ft=sSARROW;
14508 break;
14509
14510 case mfGARROW:
14511 ft=sGARROW;
14512 break;
14513
14514 case mfSBOMB:
14515 ft=sSBOMB;
14516 break;
14517
14518 case mfBOMB:
14519 ft=sBOMB;
14520 break;
14521
14522 case mfBRANG:
14523 ft=sBRANG;
14524 break;
14525
14526 case mfMBRANG:
14527 ft=sMBRANG;
14528 break;
14529
14530 case mfFBRANG:
14531 ft=sFBRANG;
14532 break;
14533
14534 case mfWANDMAGIC:
14535 ft=sWANDMAGIC;
14536 break;
14537
14538 case mfREFMAGIC:
14539 ft=sREFMAGIC;
14540 break;
14541
14542 case mfREFFIREBALL:
14543 ft=sREFFIREBALL;
14544 break;
14545
14546 case mfSWORD:
14547 ft=sSWORD;
14548 break;
14549
14550 case mfWSWORD:
14551 ft=sWSWORD;
14552 break;
14553
14554 case mfMSWORD:
14555 ft=sMSWORD;
14556 break;
14557
14558 case mfXSWORD:
14559 ft=sXSWORD;
14560 break;
14561
14562 case mfSWORDBEAM:
14563 ft=sSWORDBEAM;
14564 break;
14565
14566 case mfWSWORDBEAM:
14567 ft=sWSWORDBEAM;
14568 break;
14569
14570 case mfMSWORDBEAM:
14571 ft=sMSWORDBEAM;
14572 break;
14573
14574 case mfXSWORDBEAM:
14575 ft=sXSWORDBEAM;
14576 break;
14577
14578 case mfHOOKSHOT:
14579 ft=sHOOKSHOT;
14580 break;
14581
14582 case mfWAND:
14583 ft=sWAND;
14584 break;
14585
14586 case mfHAMMER:
14587 ft=sHAMMER;
14588 break;
14589
14590 case mfSTRIKE:
14591 ft=sSTRIKE;
14592 break;
14593
14594 default:
14595 putit = false;
14596 break;
14597 }
14598
14599 if(putit)
14600 {
14601 s->ffcs[i].data = s->secretcombo[ft];
14602 s->ffcs[i].cset = s->secretcset[ft];
14603 }
14604 }
14605 }
14606
14607 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
14608 {
14609 for(int32_t iter=0; iter<1; ++iter)
14610 {
14611 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14612
14613 if(iter==1)
14614 {
14615 // FFCs can't have flags! Yet...
14616 }
14617
14618 if((checkflag > 15)&&(checkflag < 32))
14619 {
14620 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
14621 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
14622 }
14623 }
14624 }
14625 }
14626 }
14627